Jfreechart XYAreaChart多种颜色

时间:2014-05-01 19:09:28

标签: jfreechart

好的,所以使用Jfreechart我有这两个时间序列的数据集。我希望能够选择每个时间序列使用哪种颜色。我希望第一次系列是蓝色的,下一个系列是绿色的。现在虽然图表似乎默认为蓝色和紫色,但我无法弄清楚原因。这是代码:

    public JFreeChart doProcess(final XYDataset dataset, String theDB) {
    //PlotOrientation orientation;
    final JFreeChart chart = ChartFactory.createXYAreaChart(theDB
            + " AVERAGE ACTIVE SESSION GRAPH", "DATE (MM/DD/YYYY HH:MI)", "ACTIVE SESSIONS", dataset, PlotOrientation.VERTICAL,
            true, true, false);
    chart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xFF));// light gray
    final XYPlot plot = chart.getXYPlot();
    //plot.setOutlinePaint(Color.black);
    plot.setBackgroundPaint(new Color(0xFF, 0xFF, 0xFF));
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);   
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(false);   
    plot.setForegroundAlpha(0.65f);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    DateAxis d = new DateAxis();
    d.setVerticalTickLabels(true);
    d.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    d.setDateFormatOverride(new SimpleDateFormat("MM-dd-yyyy HH:mm"));
    plot.setDomainAxis(d); 
    final ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);
    plot.getRenderer().setSeriesPaint(1, Color.GREEN);
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);
    return chart;
}

我想要做的就是将蓝色顶线和底线绿色。请帮忙。

1 个答案:

答案 0 :(得分:1)

您的代码看起来很好。您应该查看在从doProcess()方法返回之后对图表实例执行的操作。请特别注意对applyCurrentTheme()的任何调用。