Jfree chart colour change issue

Hi,

I have a chart with 4 datasets and 2 subplots (2 datasets plotted on each subplot). I want to show only shapes for subplot 1 and series 0. If I use below code, it changes the colour for both the subplots series 0.

chartObj = event.source
chart = chartObj.chart
plot = chart.getXYPlot()
	
line_shape = XYLineAndShapeRenderer()
	
line_shape.setSeriesShape(0, Rectangle2D.Double(-3, -3, 6, 6)) 	
line_shape.setSeriesShapesFilled(0, 1)									
line_shape.setSeriesLinesVisible(0, 0)						
	
plot.setRenderer(line_shape)
#print plot.getDataset(0)
plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.red)	#Sets the colour

Additionally, print plot.getDataset(0) returns None. Anyway I can make this happen only in subplot 1.

Thanks for your help.

You need to get the subplots.
plot.getSubplots()

2 Likes

Damn I didn’t think about that. Thank you very much.