XYSeriesCollection - two lines - problem

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
pulkownik
Posts: 2
Joined: Sun Apr 13, 2014 3:21 pm
antibot: No, of course not.

XYSeriesCollection - two lines - problem

Post by pulkownik » Sun Apr 13, 2014 3:27 pm

Hi everyone,

As i am not a native speaker (English) sorry for my all mistake and i have problem with find the similar issue with two lines in XYSeriesCollection.

So:

Code: Select all

XYSeries series = new XYSeries("Accumulated result");
 XYSeries series1 = new XYSeries("Index result");
here im adding points to the series and series1 using loop, then

Code: Select all

XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
dataset.addSeries(series1);
				JFreeChart chart = ChartFactory.createXYLineChart("Simulation", // Title
						"Days", // x-axis Label
						"Cumulative results", // y-axis Label
						dataset, // Dataset
						PlotOrientation.VERTICAL, // Plot Orientation
						true, // Show Legend
						true, // Use tooltips
						false // Configure chart to generate URLs?
						);
And series has numbers in thousands but series1 has numbers in hundred or less, and when i display the chart, everything is fine except the series1 is a straight line. Have anyone solution for this type of situation?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: XYSeriesCollection - two lines - problem

Post by david.gilbert » Wed Apr 16, 2014 8:33 am

You could use the CombinedDomainXYPlot and show the two datasets in separate subplots.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

pulkownik
Posts: 2
Joined: Sun Apr 13, 2014 3:21 pm
antibot: No, of course not.

Re: XYSeriesCollection - two lines - problem

Post by pulkownik » Sat Apr 19, 2014 11:54 am

Hi thanks for your response, i figured it out in anoher way. Everything is great and works fine but i have last problem. Could you give me some advice?
So here i create two dataset for two lines

Code: Select all

				DefaultCategoryDataset cumulativeResultData = new DefaultCategoryDataset();
				DefaultCategoryDataset indexResultData = new DefaultCategoryDataset();
Then in loop im using:

Code: Select all

					cumulativeResultData.addValue(cumulativeResult,"Cumulative Result", "" + days);
Days are integer number using in loop, in every step increments days + 1
Last step i create chart:

Code: Select all

				CategoryPlot plot = new CategoryPlot();
				plot.setDomainAxis(new CategoryAxis("Days"));
				plot.setRangeAxis(new NumberAxis("Result"));
				plot.setOrientation(PlotOrientation.VERTICAL);

				LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(true,
						false);
				LineAndShapeRenderer renderer = new LineAndShapeRenderer(true,
						false);

				plot.setRenderer(renderer);
				plot.setDataset(cumulativeResultData);

				ValueAxis rangeAxis2 = new NumberAxis("Index price");
				rangeAxis2.setRange(minRange - 1, maxRange + 1);
				plot.setRangeAxis(1, rangeAxis2);
				plot.setRenderer(1, renderer2);
				plot.setDataset(1, indexResultData);
				plot.mapDatasetToRangeAxis(1, 1);

				JFreeChart chart = new JFreeChart(plot);
But when i created chart for lets say 500 days, the chart looks: http://imgur.com/ExEmyOu
Axis Days is not clearly is any way to display Axis Days legend for examply not for each step in loop?
Now i have 1 2 3 4 5 6 7, i want 1 10 20 30 40 etc?

Edit:
I found solution

Code: Select all

				NumberAxis domainAxis = (NumberAxis) plot.getRangeAxis();
				domainAxis.setTickUnit(new NumberTickUnit(50));
But in my situation it does not work as in fact the domainAxis is a string not a number... Any sugestion?

Locked