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;
}
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);
}