I have been trying to plot this Stacked Bar Chart in Java using JFreeChart
for a wile now.
The problem appears when I try to add the same item "A1" after "A3". Instead of adding another "A1" it replaces the previous "A1",
I have tried to use DefaultMultiValueCategoryDataset
but could not manage to make it work.
The code I used is shown below:
DefaultCategoryDataset data = new DefaultCategoryDataset();
data.addValue(2d, "A1", "test");
data.addValue(3d, "A3", "test");
data.addValue(5d, "A2" , "test");
// If I add this it will replace the previous "A1", which is not want I want…
// data.addValue(3d, "A1", "test");
JFreeChart chart = ChartFactory.createStackedBarChart(
null,
"Question Node", // domain axis label
"Forecast Time (months/quarters/years)", // range axis label
data, // data
PlotOrientation.HORIZONTAL, // the plot orientation
true, // include legend
true, // tooltips
false // urls
);