[RESOLVED] JFreeChart in SWT resizes after display causing flicker

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ktc
Posts: 2
Joined: Fri Aug 31, 2018 12:46 pm
antibot: No, of course not.

[RESOLVED] JFreeChart in SWT resizes after display causing flicker

Post by ktc » Fri Aug 31, 2018 1:18 pm

Hello,
I am displaying JFreeChart in an Eclipse RCP/SWT application. I don't think I am doing anything fancy. I am using one of the samples to prove the concept. My chart initially displays fully including the bottom legend within the space assigned. Immediately it is resizing and shows only a part of the graph (the X axis and the legend goes out of sight, Y axis from 0 to 2.5 is not visible). This immediate resizing causes flicker. Then when the window is resized it will show the full graph within the same space. Han can I avoid this flicker? What is causing this issue?


I create chart:

Code: Select all

private JFreeChart createChart(final XYDataset dataset)
	{

		// create the chart...
		final JFreeChart chart = ChartFactory.createXYLineChart("Account Performance", // chart title
				"X", // x axis label
				"Y", // y axis label
				dataset, // data
				PlotOrientation.VERTICAL, true, // include legend
				true, // tooltips
				false // urls
		);

		// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
		chart.setBackgroundPaint(Color.white);

		// final StandardLegend legend = (StandardLegend) chart.getLegend();
		// legend.setDisplaySeriesShapes(true);

		// get a reference to the plot for further customisation...
		final XYPlot plot = chart.getXYPlot();
		plot.setBackgroundPaint(Color.lightGray);
		plot.setDomainGridlinePaint(Color.white);
		plot.setRangeGridlinePaint(Color.white);

		final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
		renderer.setSeriesLinesVisible(0, true);
		renderer.setSeriesShapesVisible(1, true);
		plot.setRenderer(renderer);

		// change the auto tick unit selection to integer units only...
		final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

		return chart;
	}
	
Then display the chart:

Code: Select all

public void createChartPanel()
	{
		final XYDataset dataset = createDataset();
		final JFreeChart chart = createChart(dataset);
		final ChartPanel chartPanel = new ChartPanel(chart);

		Frame chartFrame = SWT_AWT.new_Frame(this);
		chartFrame.layout();
		chartFrame.add(chartPanel);
	}
	

ktc
Posts: 2
Joined: Fri Aug 31, 2018 12:46 pm
antibot: No, of course not.

Re: [RESOLVED] JFreeChart in SWT resizes after display causing flicker

Post by ktc » Fri Aug 31, 2018 3:32 pm

This issue has been resolved. I was putting the chart in a JFreeChart ChartPanel, and the JFreeChart ChartPanel in a frame provided by the SWT_AWT bridge.

After a lot of digging, realized that all the SWT related code had been moved out into a separate project. I was able to pair up the latest version of the jfreechart-swt with the latest jfreechart. Then used the ChartComposite provided by the jfreechart-swt project. Examples of this can be found in the jfreechart-swt project.

Locked