1 39 40 41 package org.krysalis.jcharts.test; 42 43 44 import org.krysalis.jcharts.chartData.ChartDataException; 45 import org.krysalis.jcharts.chartData.PieChartDataSet; 46 import org.krysalis.jcharts.nonAxisChart.PieChart2D; 47 import org.krysalis.jcharts.properties.*; 48 49 import javax.swing.*; 50 import java.awt.*; 51 import java.awt.event.WindowEvent ; 52 53 54 public class SwingTest extends JFrame 55 { 56 private JPanel panel; 57 58 59 62 public SwingTest() throws ChartDataException, PropertyException 63 { 64 initComponents(); 65 } 66 67 68 71 private void initComponents() throws ChartDataException, PropertyException 72 { 73 this.setSize( 500, 500 ); 74 this.panel=new JPanel( true ); 75 this.panel.setSize( 500, 500 ); 76 this.getContentPane().add( this.panel ); 77 this.setVisible( true ); 78 79 80 String [] labels={"BMW", "Audi", "Lexus"}; 81 String title="Cars that Own"; 82 Paint[] paints={Color.blue, Color.gray, Color.red}; 83 double[] data={50d, 30d, 20d}; 84 85 PieChart2DProperties pieChart2DProperties=new PieChart2DProperties(); 86 PieChartDataSet pieChartDataSet=new PieChartDataSet( title, data, labels, paints, pieChart2DProperties ); 87 88 PieChart2D pieChart2D=new PieChart2D( pieChartDataSet, new LegendProperties(), new ChartProperties(), 450, 450 ); 89 90 93 pieChart2D.setGraphics2D( (Graphics2D) this.panel.getGraphics() ); 94 pieChart2D.render(); 95 96 97 99 100 addWindowListener( new java.awt.event.WindowAdapter () 101 { 102 public void windowClosing( WindowEvent windowEvent ) 103 { 104 exitForm( windowEvent ); 105 } 106 } 107 ); 108 } 109 110 111 116 private void exitForm( WindowEvent windowEvent ) 117 { 118 System.exit( 0 ); 119 } 120 121 122 126 public static void main( String args[] ) throws ChartDataException, PropertyException 127 { 128 new SwingTest(); 129 } 130 131 132 } 133 | Popular Tags |