}
int size = data.length;
switch (type) {
case PIE: {
// 设置填充的数据集
DefaultPieDataset dataset = new DefaultPieDataset();
for (int i = 0; i < size; i++) {
String name;
if (itemNames != null) {
name = itemNames[i];
} else {
name = data[i].toString();
i++;
}
dataset.setValue(name, Double.parseDouble(data[i].toString()));
}
chart = ChartFactory.createPieChart(title, dataset, true, false, false);
PiePlot plot = (PiePlot) chart.getPlot();
// 设置显示格式, {0}表示名称, {1}表示值, {2}表示百分比值
if (labelFormat != null) {
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
labelFormat, NumberFormat.getNumberInstance(), new DecimalFormat(
"0.0%")));
}
plot.setLabelFont(tickLabelFont);
break;
}
case VBAR:
case HBAR:
case LINE:
case SPIDER: {
// 设置填充的数据集
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
int step = 1 + (itemNames == null ? 1 : 0)
+ (groupNames != null && groupNames[0].length() == 0 ? 1 : 0);
for (int i = 0; i < size; i++) {
String name;
if (itemNames != null) {
name = itemNames[groupNames != null && groupNames[0].length() > 0 ? (i / step)
/ groupNames.length
: i * itemNames.length / size];
} else {
name = data[i].toString();
i++;
}
String category;
if (groupNames != null) {
if (groupNames[0].length() == 0) {
category = data[i].toString();
i++;
} else {
category = groupNames[((i / step) % groupNames.length)];
}
} else {
category = "";
}
dataset
.addValue(Double.parseDouble(data[i].toString()), category, name);
}
if (type == SPIDER) {
AdvancedSpiderWebPlot plot = new AdvancedSpiderWebPlot(dataset);