Never been to DZone Snippets before?

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

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Java - JFreeChart Example

   1  
   2  import java.awt.Font;
   3  
   4  import javax.swing.JFrame;
   5  import javax.swing.JPanel;
   6  
   7  import org.jfree.chart.ChartFactory;
   8  import org.jfree.chart.ChartPanel;
   9  import org.jfree.chart.JFreeChart;
  10  import org.jfree.chart.plot.PiePlot;
  11  import org.jfree.data.general.DefaultPieDataset;
  12  
  13  public class jfcExample extends JFrame
  14  {
  15  	private static final long serialVersionUID = 1L;
  16  	
  17  	private DefaultPieDataset dataset;
  18  	private JFreeChart jfc;
  19  
  20  	public jfcExample()
  21  	{
  22  		dataset = new DefaultPieDataset();
  23  	}
  24  	
  25  	public void setValue(String title, Double numDouble)
  26  	{
  27  		dataset.setValue(title, numDouble);
  28  	}
  29  	
  30  	public void setChar(String title)
  31  	{
  32  		jfc = ChartFactory.createPieChart(title, dataset, true, true, false);
  33  		
  34  		PiePlot pp = (PiePlot) jfc.getPlot();
  35  		pp.setSectionOutlinesVisible(false);
  36  		pp.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
  37  		pp.setNoDataMessage("Nessun Dato Inserito");
  38  		pp.setCircular(false);
  39  		pp.setLabelGap(0.02);
  40  	}
  41  	
  42  	private JPanel createPanel()
  43  	{
  44  		return new ChartPanel(jfc);
  45  	}
  46  	
  47  	public void Show()
  48  	{
  49  		setContentPane(createPanel());
  50  		setVisible(true);
  51  	}
  52  	
  53  	public static void main(String[] args)
  54  	{
  55  		jfcExample j = new jfcExample();
  56  		j.setTitle("Example Chart...");
  57  		j.setSize(640, 430);
  58  		
  59  		j.setValue("UNO", new Double(20.0));
  60  		j.setValue("DUE", new Double(10.0));
  61  		j.setValue("TRE", new Double(20.0));
  62  		j.setValue("QUATTRO", new Double(30.0));
  63  		j.setValue("CINQUE", new Double(20.0));
  64  		
  65  		j.setChar("Example Chart...");
  66  		
  67  		j.Show();
  68  	}
  69  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS