2014-05-01 162 views
-1

好,所以使用Jfreechart我有这两个时间序列这些数据集。我希望能够选择每个时间序列使用哪种颜色。我想第一次系列是蓝色的,下一次是绿色系列。现在虽然图似乎默认为蓝色和紫色,我不知道为什么。这里是代码:Jfreechart XYAreaChart多种颜色

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

你的代码看起来不错。你应该看看你对图表实例做了什么后,它从doProcess()方法返回。尤其要注意拨打applyCurrentTheme()