JFreeChart Get Plot Example
Chapter:
JFreeChart
Last Updated:
07-07-2016 13:52:31 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 JavaJFreeChartPlotAttribute {
public static void main(String[] args) {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("JAVA", 40.1);
dataset.setValue("C#", 22);
dataset.setValue("C++", 81);
// Creation Of Chart.
JFreeChart chart = ChartFactory.createPieChart("Programming Languages", dataset, true, // legend?
true, // tooltips?
false // URLs?
);
ChartFrame frame = new ChartFrame("JFreeChart", chart);
Plot plot = chart.getPlot();
/* You can use the below method also for getting Plot
CategoryPlot plot = chart.getCategoryPlot();
XYPlot plot = chart.getXYPlot();
*/
frame.pack();
frame.setVisible(true);
}
}
/* ............... END ............... */
Notes:
-
The getPlot() method in the JFreeChart class returns a reference to the plot being used by the chart.
- Methods will throw a ClassCastException if the plot is not an appropriate class.
Tags
JFreeChart Get Plot Class, Java