10

I need to create a simple histogram using JFreeChart. There should be 3 groups with numeric values assigned to each of these groups. The problem is that DefaultCategoryDataset requires specifying "Group" and "Subgroup" (i.e. dataset.setValue(5,"Subgroup1.1","Group1");), but I don´t have subgroups. What is the alternative of DefaultCategoryDataset? I need to get something like this:

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(2, "Group1");
dataset.setValue(3, "Group2");
dataset.setValue(5, "Group3");
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217
  • 4
    I found the solution to my problem. An example is given here http://www.java2s.com/Code/Java/Chart/JFreeChartXYSeriesDemo3.htm – Klausos Klausos Jan 16 '12 at 10:06

1 Answers1

1

You can just use the same row key for each bin and vary the column key, like this:

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(561, "Age", "1 - 10");
dataset.addValue(1231, "Age", "10 - 20");
dataset.addValue(12323, "Age", "20+");
J. Lenthe
  • 1,330
  • 10
  • 10