2 axis on XYLineChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
xeno

2 axis on XYLineChart

Post by xeno » Mon Sep 12, 2005 4:53 pm

hi,

i need 2 axis on a XYLineChart,
i read this thread http://www.jfree.org/phpBB2/viewtopic.php?t=12244
but for XYLineChart it doesn't work

here is my code:

Code: Select all

//		 Add the series to your data set
		XYSeriesCollection dataset = new XYSeriesCollection();
		XYSeries[] s=new XYSeries[series.length];
		s=getXYSeries();
		
		for(int i=0 ; i<(s.length-1) ; i++) {
			dataset.addSeries(s[i]);	
		}		
		
//		 Generate the graph
		JFreeChart chart = ChartFactory.createXYLineChart(
		title, // Title
		xLabel, // x-axis Label
		yLabel, // y-axis Label
		dataset, // Dataset
		PlotOrientation.VERTICAL, // Plot Orientation
		true, // Show Legend
		false, // Use tooltips
		false // Configure chart to generate URLs?
		);
	     
	      
		try {	ChartUtilities.saveChartAsPNG(new File(nomedir + "/graph.png"), chart, xDim, yDim);	} 
		catch (IOException e) {	System.err.println("Problem occurred creating chart."); 	}

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Tue Sep 13, 2005 7:18 am

In your code you have nothing which adds a second axis, so of course it doesn't work.

Guest

Post by Guest » Tue Sep 13, 2005 11:13 am

that is the code i used for the second axis but i have a cast error in the line with the *.
i think XYSeries use another type of plot and dataset but i don't know...

Code: Select all

DefaultCategoryDataset secondaryDataset = new DefaultCategoryDataset();
secondaryDataset.addValue(0.3,"birgi","Category 1");
secondaryDataset.addValue(0.95,"damla","Category 2"); 
CategoryPlot plot = chart.getCategoryPlot();  //*
NumberAxis axis2 = new NumberAxis("Satis Yüzdesi");
plot.setRangeAxis(1, axis2);
plot.setDataset(1, secondaryDataset);
 LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(true,true);
 plot.setRenderer(1, lineRenderer);
plot.mapDatasetToRangeAxis(1, 1);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); 
thanks for answering

erikvanoosten
Posts: 8
Joined: Tue Aug 30, 2005 10:42 am

Post by erikvanoosten » Tue Sep 13, 2005 11:31 am

Indeed, you probably have an XYPlot.

Guest

Post by Guest » Tue Sep 13, 2005 11:51 am

so i have to use XYSeriesCollection for the dataset and XYPlot for the plot and the methods are the same.

Ok thanks

erikvanoosten
Posts: 8
Joined: Tue Aug 30, 2005 10:42 am

Post by erikvanoosten » Tue Sep 13, 2005 12:00 pm

Yes.

Or, you can create a category chart. Do you have the manual? It will make your life a lot easier.

Guest

Post by Guest » Tue Sep 13, 2005 1:24 pm

unfortunatly i don't have the manual,

i am a student and i don't make commercial software so for me is a little expensive...

erikvanoosten
Posts: 8
Joined: Tue Aug 30, 2005 10:42 am

Post by erikvanoosten » Tue Sep 13, 2005 2:10 pm

Your first choice is to either make a category or an XY chart. As a rule of thumb: select a category chart when you have groups of data on the domain axis and select an XY chart when your domain axis represents some continuous domain.

For the category chart you can call ChartFactory.createLineChart(), for the xy chart you can call ChartFactory.createXYLineChart(). The first contains a CategoryPlot, the second an XYPlot.

Locked