JFreeChart Background Paint Example
Chapter:
JFreeChart
Last Updated:
07-07-2016 14:03:03 UTC
Program:
/* ............... START ............... */
import java.awt.Color;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Plot;
import org.jfree.data.general.DefaultPieDataset;
public class JavaJFreeChartBackgroundPaint {
public static void main(String[] args) {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Audi", 40.1);
dataset.setValue("BMW", 22);
dataset.setValue("TOYOTA", 81);
// Creation Of Chart.
JFreeChart chart = ChartFactory.createPieChart("Cars", dataset, true, // legend?
true, // tooltips?
false // URLs?
);
ChartFrame frame = new ChartFrame("JFreeChart", chart);
Plot plot = chart.getPlot();
plot.setBackgroundPaint(Color.yellow);
frame.pack();
frame.setVisible(true);
}
}
/* ............... END ............... */
Output
Notes:
-
setBackgroundPaint() method to set the background color for a plot.
- You can also set the background paint to null.
Tags
JFreeChart Background Paint, Java