Hi Igniteflow,
Download Jfreechar from here
Download JFreeChart from SourceForge.net
once downloaded extract the file onto your desktop!,once extracted,open up netbeans -> right click on the libraries(place on left side of your netbeans project)->select add jar/folder->dialog box pops up,navigate to the lib folder of your downloaded jfreechart-1.0.13,and add them all.now all the required libraries are placed.
Once you are done with that,try this code out!
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.util.Rotation;
public class PieChart extends JFrame {
public PieChart(String applicationTitle, String chartTitle) {
super(applicationTitle);
// This will create the dataset
PieDataset dataset = createDataset();
// based on the dataset we create the chart
JFreeChart chart = createChart(dataset, chartTitle);
// we put the chart into a panel
ChartPanel chartPanel = new ChartPanel(chart);
// default size
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
// add it to our application
setContentPane(chartPanel);
}
/**
* Creates a sample dataset
*/
private PieDataset createDataset() {
DefaultPieDataset result = new DefaultPieDataset();
result.setValue("Linux", 50);
result.setValue("Mac", 20);
result.setValue("Windows", 51);
return result;
}
/**
* Creates a chart
*/
private JFreeChart createChart(PieDataset dataset, String title) {
JFreeChart chart = ChartFactory.createPieChart3D(
title, // chart title
dataset, // data
true, // include legend
true,
false
);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.5f);
return chart;
}
}
class Main
{
public static void main(String[] args) {
PieChart demo = new PieChart("Comparison", "Which operating system are you using?");
demo.pack();
demo.setVisible(true);
}
}
Kind Regards,
Manish87