XChart
XChart copied to clipboard
Incorrect x-axis value for multiple histogram
I am trying to create a chart with 2 histogram data. The first set of data is [0,1,2], and the second set is [-2,-1, 0]
However, the chart wasn't as I expected. The expected x-axis I expected is [-2,-1,0,1,2], however, the x-axis value returned is [0,1,2] Is there's anything I can do to fix the issue? Thanks

// Create Chart
CategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("Score Histogram")
.xAxisTitle("Mean").yAxisTitle("Count").build();
// Customize Chart
chart.getStyler().setLegendPosition(Styler.LegendPosition.InsideNW);
chart.getStyler().setXAxisMaxLabelCount(10);
chart.getStyler().setXAxisDecimalPattern("0.0");
chart.getStyler().setStacked(true);
// Series
Histogram histogram1 = new Histogram(Arrays.asList(0, 1, 2), 100);
chart.addSeries("Price", histogram1.getxAxisData(), histogram1.getyAxisData());
Histogram histogram2 = new Histogram(Arrays.asList(-2, -1, 0), 100);
chart.addSeries("Percentage ", histogram2.getxAxisData(), histogram2.getyAxisData());
@bwong43
CategoryChart
multiple series, the x-axis calculation takes the first series.
@timmolter
When CategoryChart
adds multiple series, the xData value is not the same, the problem mentioned above will appear.
The way it works now is that you have to pass in null Y-Axis values and have matching X-Axis value for ll added series. Something like:
chart.addSeries("female", Arrays.asList(10, 20, 30, 40, 50), Arrays.asList(50, 10, 20, 40, 35));
chart.addSeries("male", Arrays.asList(10, 20, 30, 40, 50), Arrays.asList(40, 30, 20, null, 60));
However, I think your way is what most people would expect to "just work". I'll leave this open as a feature request...