DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (Object obj : data) {
Map result = (Map)obj;
if (result.values().size() < 2)
throw new BadDataForChartException("For chart, must have at least two columns of data," +
" with the first column having the categories and the other columns having the data ");
boolean weAreAtTheFirstColumn = true;
String dataName = "";
for (Object entryObj : result.entrySet()) {
Map.Entry entry = (Map.Entry)entryObj;
Object datum = entry.getValue();
String columnName = (String)entry.getKey();
if (weAreAtTheFirstColumn) {
if (!(datum instanceof String))
throw new BadDataForChartException("First column must be a string, isstead it's " + datum.getClass().toString());
dataName = (String)datum;
weAreAtTheFirstColumn = false;
} else {
if (! ((datum instanceof BigDecimal) || (datum instanceof BigInteger)) )
throw new BadDataForChartException("Data must be decimal or integer. Can't plot otherwise.");
// add the value to the dataset:
dataset.addValue((Number)datum,columnName,dataName);
}
}