在下面的示例中,Eden是索引处的系列,索引处的0幸存者和1索引处的旧2。
例如,Old是图表中最顶部的系列,而Eden位于底部。
我想要实现的是,Eden是堆叠图表中最顶部的系列,Survivor位于中间,Old位于底部。尽管如此,Eden应该是传说中的第一个条目,而Old应该是最后一个条目。
我目前使用以下类来创建我的图表:
public class JFreeChartFactory {
private static String fontName = "Palatino";
private static Color[] chartSeriesColors = {
new Color(0.0f, 1.0f, 0.0f, 0.9f),
new Color(0.0f, 0.0f, 1.0f, 0.9f),
new Color(1.0f, 0.0f, 0.0f, 0.9f),
};
public static JFreeChart createStackedXYAreaChart(String title, String subTitle, String xAxis, String yAxis, TableXYDataset dataset) {
JFreeChart chart = ChartFactory.createStackedXYAreaChart(
title,
xAxis,
yAxis,
dataset);
chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
if (subTitle != null) {
chart.addSubtitle(new TextTitle(subTitle, new Font(fontName, Font.PLAIN, 14)));
}
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDomainPannable(true);
plot.setRangePannable(true);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
plot.getDomainAxis().setLowerMargin(0.0);
plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
chart.getLegend().setFrame(BlockBorder.NONE);
chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
for (int i = 0; i < plot.getRendererCount(); i++) {
XYItemRenderer renderer = plot.getRenderer(i);
switch (renderer.getClass().getSimpleName()) {
case "StackedXYAreaRenderer2":
StackedXYAreaRenderer2 stackedRenderer = (StackedXYAreaRenderer2) renderer;
for (int cId = 0; cId < chartSeriesColors.length; cId++) {
stackedRenderer.setSeriesPaint(cId, chartSeriesColors[cId]);
}
break;
}
}
return chart;
}
}
