I'm trying to make a bar chart wi开发者_StackOverflowth two Y-axes. The problem is that the two datasets overlap, like this:
What I want is something like this: (but with the right Y-axis mapped to the second dataset)
I'd like to solve this without using the workaround shown in the demos (edit: specifically JFreeChart: Dual Axis Demo 5), where you add null values to the datasets to shift the bars into position. This solution would be very complicated to implement with the way I process data into datasets.
Can anyone give me some pointers?
In case anyone has the same problem, here's one solution: http://www.java2s.com/Code/Java/Chart/JFreeChartDualAxisDemo5.htm
Basically, for each series you make, add a null value of the other series. Example:
In series 1:
dataset.addValue(1.0, series1, category1);
dataset.addValue(4.0, series1, category2);
dataset.addValue(3.0, series1, category3);
dataset.addValue(5.0, series1, category4);
dataset.addValue(null, series2, category1);
dataset.addValue(null, series2, category2);
dataset.addValue(null, series2, category3);
dataset.addValue(null, series2, category4);
In series 2:
dataset.addValue(null, series1, category1);
dataset.addValue(null, series1, category2);
dataset.addValue(null, series1, category3);
dataset.addValue(null, series1, category4);
dataset.addValue(75.0, series2, category1);
dataset.addValue(87.0, series2, category2);
dataset.addValue(96.0, series2, category3);
dataset.addValue(68.0, series2, category4);
精彩评论