程式扎記: [ Java 代碼範本 ] JFreeChart : XY Charts - XYLineAndShapeRendererDemo1

標籤

2015年8月10日 星期一

[ Java 代碼範本 ] JFreeChart : XY Charts - XYLineAndShapeRendererDemo1

Source From Here 
UI 效果: (jfreechart-1.0.14) 
 

範例代碼: 
- XYLineAndShapeRendererDemo1.java 
  1. package xycharts  
  2.   
  3. import java.awt.Dimension;  
  4. import javax.swing.JPanel;  
  5. import org.jfree.chart.*;  
  6. import org.jfree.chart.labels.StandardXYToolTipGenerator;  
  7. import org.jfree.chart.plot.PlotOrientation;  
  8. import org.jfree.chart.plot.XYPlot;  
  9. import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;  
  10. import org.jfree.data.xy.*;  
  11. import org.jfree.ui.ApplicationFrame;  
  12. import org.jfree.ui.RefineryUtilities;  
  13.   
  14. class XYLineAndShapeRendererDemo1 extends ApplicationFrame{  
  15.     /** 
  16.      * 
  17.      */  
  18.     private static final long serialVersionUID = 1L;  
  19.      
  20.     public XYLineAndShapeRendererDemo1(String s)  
  21.     {  
  22.         super(s);  
  23.         XYDataset xydataset = createDataset();  
  24.         JFreeChart jfreechart = createChart(xydataset);  
  25.         ChartPanel chartpanel = new ChartPanel(jfreechart);  
  26.         chartpanel.setPreferredSize(new Dimension(500300));  
  27.         setContentPane(chartpanel);  
  28.     }  
  29.      
  30.     private static JFreeChart createChart(XYDataset xydataset)  
  31.     {  
  32.         JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 1""X""Y", xydataset, PlotOrientation.VERTICAL, truetruefalse);  
  33.         XYPlot xyplot = (XYPlot)jfreechart.getPlot();  
  34.         XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();  
  35.         xylineandshaperenderer.setSeriesLinesVisible(0true);  
  36.         xylineandshaperenderer.setSeriesShapesVisible(0false);  
  37.         xylineandshaperenderer.setSeriesLinesVisible(1false);  
  38.         xylineandshaperenderer.setSeriesShapesVisible(1true);  
  39.         xylineandshaperenderer.setToolTipGenerator(new StandardXYToolTipGenerator());  
  40.         xylineandshaperenderer.setDefaultEntityRadius(6);  
  41.         xyplot.setRenderer(xylineandshaperenderer);  
  42.         return jfreechart;  
  43.     }  
  44.      
  45.     private static XYDataset createDataset()  
  46.     {  
  47.         XYSeries xyseries = new XYSeries("Series 1");  
  48.         xyseries.add(1.0D, 3.2999999999999998D);  
  49.         xyseries.add(2D, 4.4000000000000004D);  
  50.         xyseries.add(3D, 1.7D);  
  51.         XYSeries xyseries1 = new XYSeries("Series 2");  
  52.         xyseries1.add(1.0D, 7.2999999999999998D);  
  53.         xyseries1.add(2D, 6.7999999999999998D);  
  54.         xyseries1.add(3D, 9.5999999999999996D);  
  55.         xyseries1.add(4D, 5.5999999999999996D);  
  56.         XYSeriesCollection xyseriescollection = new XYSeriesCollection();  
  57.         xyseriescollection.addSeries(xyseries);  
  58.         xyseriescollection.addSeries(xyseries1);  
  59.         return xyseriescollection;  
  60.     }  
  61.      
  62.     public static JPanel createDemoPanel()  
  63.     {  
  64.         JFreeChart jfreechart = createChart(createDataset());  
  65.         return new ChartPanel(jfreechart);  
  66.     }  
  67.      
  68.     public static void main(String[] args)  
  69.     {  
  70.         XYLineAndShapeRendererDemo1 xylineandshaperendererdemo1 = new XYLineAndShapeRendererDemo1("XYLineAndShapeRenderer Demo");  
  71.         xylineandshaperendererdemo1.pack();  
  72.         RefineryUtilities.centerFrameOnScreen(xylineandshaperendererdemo1);  
  73.         xylineandshaperendererdemo1.setVisible(true);  
  74.     }  
  75. }  

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!