Java - JFreeChart Example


/ Published in: Java
Save to your folder(s)



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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.