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!
number of categories does not match data
Re: number of categories does not match data
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.
percent = new double[1]; //create sub-array
Since there is only space for one value, you can only have one category.
Regards,
DG.