Just trying to work on my graphs and I've been stuck on this one graph.
I currently have the following graph:

I am trying to get my graph to have a background color of green at all points below the yellow area in my graph, I've tinkered with XYDifference but it does not seem to generate a result that I like.
I have the following code:
Code: Select all
DefaultTableXYDataset dataset = new DefaultTableXYDataset();
XYSeries s1 = new XYSeries("2SD", false, false);
s1.add(1, 0.9);
s1.add(2, 1.7);
s1.add(3, 1.8);
s1.add(4, 1.9);
s1.add(5, 2.1);
XYSeries s2 = new XYSeries("3SD", false, false);
s2.add(1, 0.4);
s2.add(2, 0.7);
s2.add(3, 0.7);
s2.add(4, 0.9);
s2.add(5, 1);
dataset.addSeries(s1);
dataset.addSeries(s2);
JFreeChart chart = org.jfree.chart.ChartFactory.createStackedXYAreaChart(
"TESTING",
"X",
"Y",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
StackedXYAreaRenderer renderer = new StackedXYAreaRenderer();
renderer.setSeriesPaint(0, Color.GREEN);
renderer.setSeriesPaint(1, Color.YELLOW);
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
plot.setRenderer(0, renderer);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
plot.setBackgroundPaint(Color.RED);
plot.setRangeGridlinesVisible(false);
plot.setDomainGridlinesVisible(false);
plot.setDomainPannable(false);
plot.setRangePannable(false);
ValueAxis xAxis = plot.getDomainAxis();
xAxis.setRange(1, 5);
return new ChartViewer(chart);
Also, is there a way to disable zooming on ChartViewer? (using ChartViewer because of JavaFX)
Thanks.