1

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
    );
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • This is the expected behavior for existing row and column key. See this related [example](https://stackoverflow.com/a/31166200/230513) that uses six distinct column keys. – trashgod Dec 07 '18 at 17:56
  • Please [edit] your question to include a [mcve] that exhibits the problem you describe and shows you `KeyToGroupMap`. – trashgod Dec 07 '18 at 18:09

0 Answers0