DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Java - JFreeChart Example

11.01.2006
| 48208 views |
  • submit to reddit
        
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;

public class jfcExample extends JFrame
{
	private static final long serialVersionUID = 1L;
	
	private DefaultPieDataset dataset;
	private JFreeChart jfc;

	public jfcExample()
	{
		dataset = new DefaultPieDataset();
	}
	
	public void setValue(String title, Double numDouble)
	{
		dataset.setValue(title, numDouble);
	}
	
	public void setChar(String title)
	{
		jfc = ChartFactory.createPieChart(title, dataset, true, true, false);
		
		PiePlot pp = (PiePlot) jfc.getPlot();
		pp.setSectionOutlinesVisible(false);
		pp.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
		pp.setNoDataMessage("Nessun Dato Inserito");
		pp.setCircular(false);
		pp.setLabelGap(0.02);
	}
	
	private JPanel createPanel()
	{
		return new ChartPanel(jfc);
	}
	
	public void Show()
	{
		setContentPane(createPanel());
		setVisible(true);
	}
	
	public static void main(String[] args)
	{
		jfcExample j = new jfcExample();
		j.setTitle("Example Chart...");
		j.setSize(640, 430);
		
		j.setValue("UNO", new Double(20.0));
		j.setValue("DUE", new Double(10.0));
		j.setValue("TRE", new Double(20.0));
		j.setValue("QUATTRO", new Double(30.0));
		j.setValue("CINQUE", new Double(20.0));
		
		j.setChar("Example Chart...");
		
		j.Show();
	}
}
    

Comments

Hariprasath Ven... replied on Tue, 2013/12/03 - 3:59am

 Would you please post the exact printstacktrace...


Snippets Manager replied on Fri, 2012/03/30 - 12:59am

Plz tell me how to run this.. First i compiled this.. no errors.. then while running it shows no class found error..