Plot with gridline on top of XYDifferenceRenderer

Go To


I'm making (time series) moutain chart using JFreeChart. So, i made 2 timeseries - the data one and the one with all range values are zero.

  TimeSeriesCollection dataset2 = new TimeSeriesCollection();
  dataset2.addSeries(close); //my data series/
  dataset2.addSeries(zeroseries); /zero series/

Then, i used XYDifferenceRenderer to fill the gap between 2 series with my desired color.

Code to create the chart and set renderer :

  final JFreeChart chart = garch_differencechart(url);//my method to create the chart//
  final ChartPanel chartPanel = new ChartPanel(chart);
  final XYPlot plot = (XYPlot) chart.getPlot();
  XYDifferenceRenderer renderer = new XYDifferenceRenderer();
  renderer.setPositivePaint(new Color(202, 225, 255));
  renderer.setSeriesPaint(0, new Color(72, 118, 255));
  renderer.setSeriesStroke(0, new BasicStroke(1.2f));

Code to set GridLines visible :

 plot.setDomainGridlinePaint(new Color(234,234,234));
 plot.setDomainGridlineStroke(new BasicStroke(0.5f));

 plot.setRangeGridlinePaint(new Color(234,234,234));
 plot.setRangeGridlineStroke(new BasicStroke(0.5f));

enter image description hereHowever, the renderer covered the plot's gridline (it seems that the gridline was painted before the XYDifferenceRenderer).

How could I get the plot with gridline on top of XYDifferenceRenderer?

2012-04-04 02:57


The gridlines show though in the demos and API. An sscce would be dispositive, but I suspect your grid and fill paints just need more contrast.

2012-04-04 03:24
by trashgod
@trashgold : I editted by question - TU_HEO DAKAI 2012-04-04 05:18
Yes, in HSB space, those colors are quite close, with both having very low saturation. To get the gridlines on top, you'd have to change the rendering order specified in <code>draw()</code> - trashgod 2012-04-04 05:22
@trashgold : So, I must subclass XYPlot to override draw() method? But i can't find any method in JFreeChart class to set my plot, something like : chart.setPlot(//my subclass//) - TU_HEO DAKAI 2012-04-04 05:31
I'd just change the contrast, but the source of the ChartFactory you're using shows how to specify the plot - trashgod 2012-04-04 05:38
@trashgold : sorry, but i couldn't find the way to do that in ChartFactory, could you give me more hint - TU_HEO DAKAI 2012-04-04 05:56