}
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);
chart = new JFreeChart(title, titleFont, plot, groupNames != null);
if (labelFormat != null) {
plot.setLabelGenerator(new StandardCategoryItemLabelGenerator(
labelFormat, NumberFormat.getNumberInstance(), new DecimalFormat(
"0.0%")));
}
plot.setLabelFont(labelFont);
if (keys != null) {
plot.setMaxValue(Double.parseDouble(keys[0]));
}
} else {
if (type == LINE) {
chart = ChartFactory.createLineChart(title, keys[0], keys[1],
dataset, PlotOrientation.VERTICAL, groupNames != null, false,
false);
} else {
chart = ChartFactory.createBarChart(title, keys[0], keys[1], dataset,
type == VBAR ? PlotOrientation.VERTICAL
: PlotOrientation.HORIZONTAL, groupNames != null, false,
false);
}
CategoryPlot plot = chart.getCategoryPlot();
// 设置显示值的数字
AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) plot
.getRenderer();
if (labelFormat != null) {
renderer.setBaseItemLabelFont(labelFont);
renderer.setBaseItemLabelsVisible(true);
renderer
.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
}
if (type == LINE) {
// 线条模式设置显示节点图形
((LineAndShapeRenderer) renderer).setBaseShapesVisible(true);
}
// 设置数值轴的信息
{
NumberAxis axis = (NumberAxis) plot.getRangeAxis();
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
axis.setUpperMargin(0.12D);
axis.setLabelFont(labelFont);
axis.setTickLabelFont(tickLabelFont);
}
// 设置分类/标题轴的信息
{
CategoryAxis axis = plot.getDomainAxis();
axis.setLabelFont(labelFont);
axis.setTickLabelFont(tickLabelFont);
}
}
break;