Changing background colour of jFreeChart
ChartPanel inherit method javax.swing.JComponent.setBackground(java.awt.Color)
chartPanel.setBackground( Color.RED );
Or try:
chart.getPlot().setBackgroundPaint( Color.BLUE );
See documentation of JFreeChart.getPlot() and Plot.setBackgroundPaint()
See this post on SO or this one too.
You have to use JFreeChart.getPlot().setBackgroundPaint(Color.WHITE);
like this:
public static void main(String[] args) {
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("LoggedIn" +": "+ 5, 10);
pieDataset.setValue("LoggedOut" +": "+ 8, 17);
JFreeChart jfc = ChartFactory.createPieChart("title", pieDataset, false, false, false );
jfc.getPlot().setBackgroundPaint(Color.WHITE);
ChartPanel chart = new ChartPanel(jfc);
JFrame frame = new JFrame();
frame.add(chart);
frame.pack();
frame.setVisible(true);
}
I hope it helps!