XYDifferenceRenderer doesn't color the entire area

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
trequick
Posts: 2
Joined: Sat Sep 20, 2014 1:19 pm
antibot: No, of course not.

XYDifferenceRenderer doesn't color the entire area

Post by trequick » Sat Sep 20, 2014 1:29 pm

Image

As you can see in the image, for each time point I have five values. The goal is to have the median value in black, enclosed by a first band in gray, additionally enclosed in a second band in light gray. I draw the median value with an XYLineAndShapeRenderer, and both bands with a separate XYDifferenceRenderer. So far so good.

However, for some reason the XYDifferenceRenderers don't color the entire difference area. As you can see in the image, both XYDifferenceRenderers have this problem, although it happens at different values.

I have no idea what causes this or how to solve it, so I welcome any help.

This is my relevant code:

Code: Select all

// add data
XYSeries medianSeries = new XYSeries("Median");
XYSeries q1Series = new XYSeries("Q1");
XYSeries q3Series = new XYSeries("Q3");
XYSeries minSeries = new XYSeries("Min");
XYSeries maxSeries = new XYSeries("Max");
for(Value value : values) {
	medianSeries.add(value.getFromRun().getSampleDate().getTime(), value.getMedian());
	q1Series.add(value.getFromRun().getSampleDate().getTime(), value.getQ1());
	q3Series.add(value.getFromRun().getSampleDate().getTime(), value.getQ3());
	minSeries.add(value.getFromRun().getSampleDate().getTime(), value.getMin());
	maxSeries.add(value.getFromRun().getSampleDate().getTime(), value.getMax());
}

XYSeriesCollection medianCollection = new XYSeriesCollection(medianSeries);
XYSeriesCollection q1q3Collection = new XYSeriesCollection();
q1q3Collection.addSeries(q1Series);
q1q3Collection.addSeries(q3Series);
XYSeriesCollection minMaxCollection = new XYSeriesCollection();
minMaxCollection.addSeries(minSeries);
minMaxCollection.addSeries(maxSeries);

// renderer
XYItemRenderer medianRenderer = new XYLineAndShapeRenderer();
medianRenderer.setSeriesPaint(0, Color.BLACK);
medianRenderer.setSeriesShape(0, new Ellipse2D.Double(-2, -2, 4, 4));
XYDifferenceRenderer q1q3Renderer = new XYDifferenceRenderer(Color.GRAY, Color.GRAY, true);
q1q3Renderer.setSeriesPaint(0, Color.GRAY);
q1q3Renderer.setSeriesPaint(1, Color.GRAY);
q1q3Renderer.setSeriesShape(0, new Ellipse2D.Double(-2, -2, 4, 4));
q1q3Renderer.setSeriesShape(1, new Ellipse2D.Double(-2, -2, 4, 4));
XYDifferenceRenderer minMaxRenderer = new XYDifferenceRenderer(Color.LIGHT_GRAY, Color.LIGHT_GRAY, true);
minMaxRenderer.setSeriesPaint(0, Color.LIGHT_GRAY);
minMaxRenderer.setSeriesPaint(1, Color.LIGHT_GRAY);
minMaxRenderer.setSeriesShape(0, new Ellipse2D.Double(-2, -2, 4, 4));
minMaxRenderer.setSeriesShape(1, new Ellipse2D.Double(-2, -2, 4, 4));

// create axis
DateAxis dateAxis = new DateAxis("Date");
dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
dateAxis.setVerticalTickLabels(true);

NumberAxis valueAxis = new NumberAxis("Value");
valueAxis.setAutoRangeIncludesZero(false);

// create plot and draw graph
XYPlot plot = new XYPlot();
plot.setDomainAxis(dateAxis);
plot.setRangeAxis(valueAxis);
plot.setDataset(0, medianCollection);
plot.setDataset(1, q1q3Collection);
plot.setDataset(2, minMaxCollection);
plot.setRenderer(0, medianRenderer);
plot.setRenderer(1, q1q3Renderer);
plot.setRenderer(2, minMaxRenderer);
JFreeChart chart = new JFreeChart(valueName, plot);
chart.setBackgroundPaint(Color.WHITE);
chartPanel = new ChartPanel(chart, false, true, false, true, false);
chart.removeLegend();

trequick
Posts: 2
Joined: Sat Sep 20, 2014 1:19 pm
antibot: No, of course not.

Re: XYDifferenceRenderer doesn't color the entire area

Post by trequick » Tue Sep 23, 2014 1:15 pm

Ok, seems like there was an obvious solution. Apparently I was using an unofficial Maven entry to add JFreeChart to my project, and I was still using version 1.0.13. I've updated to version 1.0.19 now, and the issue seems mostly resolved.

Now the whole area is colored, however for some specific values (not all of them), their is a slight interruption in the color (see the image). Luckily this is less of an issue than the previous problem, but it's still a bit strange though.

Image

Locked