number of categories does not match data

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ann

number of categories does not match data

Post by Ann » Mon Aug 19, 2002 10:35 am

I made a servlet that is supposed to generate a horizontal bar chart. My code below is based from the HorizontalBarChartDemo. However, whenever I execute my code below, I get the following error:

java.lang.IllegalArgumentException:DefaultCategoryDataset.setCategories(...): the number of categories does not match the data.

HttpSession session = request.getSession();
listpos = (ArrayList) session.getAttribute("listpos");
listrace = (ArrayList) session.getAttribute("listrace");

// create a dataset...

double[][] percent = new double[listrace.size()][];

//populate matrix
for (int i = 0; i < listrace.size(); i++) {
arace = (String[])listrace.get(i);
percent = new double[1]; //create sub-array
percent[0] = Double.parseDouble(arace[1]);
}

DefaultCategoryDataset dataset = new DefaultCategoryDataset(percent);

String[] candi = new String[listrace.size()];

// set the series names = candidate names
for(int i=0; i < listrace.size(); i++) {
arace = (String[])listrace.get(i);
candi = arace[0];
dataset.setSeriesName(i, candi);
}

// set the category names...
String[] pos = new String[listpos.size()];
System.out.println(listpos.size());
for(int i=0; i < listpos.size(); i++) {
apos = (String[])listpos.get(i);
pos = apos[0];
dataset.setCategories(pos);
}

Any help will be greatly appreciated. Thanks!

David Gilbert

Re: number of categories does not match data

Post by David Gilbert » Mon Aug 19, 2002 3:22 pm

This is the line where you create storage for the datavalues in each category:

percent = new double[1]; //create sub-array

Since there is only space for one value, you can only have one category.

Regards,

DG.

Ann

Re: number of categories does not match data

Post by Ann » Tue Aug 20, 2002 3:12 am

Thanks for the help. I really appreciate it. :)

Locked