JFreeChart development with cewolf WEB + graphics statements (1)

  Please respect the hard work I Qiaozi, annotated reprint author ronghao100 
  In the use of cewolf before, first of all, to get to know jFreeChart.    JFreeChart here to introduce three parts.    JFreeChart have introduced the first part of the process and related graphics important; on the second part of four kinds of statements map (Bingtu, histogram, polyline maps, time-series); graphical presentation at the third part of the increase in Item Lable . 
  JFreeChart version is 1.0.0-pre2 jfreechart-(1) 
  Cewolf is the latest version 0.12.0-cewolf 

  First, the process of jFreeChart generated graphics 
  Create a data source (dataset) to be included in the graphical display of data ?????>> JFreeChart object to the creation of a representative to display graphics 
  ??????>> The graphics output 
  And interfaces important category: 
  Org.jfree.data.general.Dataset all the data source categories to achieve Interface 
  Org.jfree.chart.ChartFactory from its target to produce JFreeChart 
  Org.jfree.chart.JFreeChart all of the graphics are adjusted through its Oh!    ! 
  Org.jfree.chart.plot.Plot get it through JFreeChart object, and then through its graphical external part (Example: coordinate axis) Adjustment 
  Note: it has many sub-categories, the general shape of most of the sub-class that it! 
  Org.jfree.chart.renderer.AbstractRenderer get it through JFreeChart object, and then the internal part of its graphics 
  (Example: Folding type) adjustment.    Similarly, the different types of statements map, it 
  A different type of achieving!    Below we have it in the short for the Renderer 
  Below we combine different types of graphics to specific analysis of this process. 

  Second, Bingtu 
  Bingtu the dataset is generally used PieDataset interface, is the concrete realization of DefaultPieDataset 
  1, the creation of a data source (dataset): 
  Private static PieDataset createDataset () 
  ( 
  DefaultPieDataset defaultpiedataset = new DefaultPieDataset () / / is DefaultPieDataset attention!    ! 
  Defaultpiedataset.setValue ( "One", the new Double (43.200000000000003D)); 
  Defaultpiedataset.setValue ( "Two", the new Double (10D)); 
  Defaultpiedataset.setValue ( "Three" new Double (27.5D)); 
  Defaultpiedataset.setValue ( "Four", the new Double (17.5D)); 
  Return defaultpiedataset; 
  ) 
  2, produced by JFreeChart object ChartFactory 
  Private static JFreeChart createChart (PieDataset piedataset) 
  ( 
  JFreeChart jfreechart = ChartFactory.createPieChart ( "Pie Chart Demo 1", / / graphics titles 
  Piedataset, / / dataset 
  True, / / legend? 
  True, / / tooltips? 
  False); / / URLs? 
  PiePlot pieplot = (PiePlot) jfreechart.getPlot (); / / object obtained through JFreeChart plot: PiePlot!    ! 
  Pieplot.setNoDataMessage ( "No data available"); / / no data showed that the contents of the time 
  Return jfreechart; 
  ) 
  A number of important ways: 
  Pieplot.setExplodePercent (0,0.3 D) / / Lable to the "One" that a "dig" up 30% 
  3, the output slightly 

  3, column 
  The dataset column is generally used CatagoryDataset Interface (concrete realization is the DefaultCategoryDataset), will be used IntervalXYDataset 
  Interface 
  1, the creation of a data source (dataset): 
  Private static CategoryDataset createDataset () 
  ( 
  String series1 = "First"; 
  String series2 = "Second"; 
  String series3 = "Third"; 
  String category1 = "Category 1"; 
  String category2 = "Category 2"; 
  String category3 = "Category 3"; 
  String category4 = "Category 4"; 
  String category5 = "Category 5"; 
  DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset (); 
  Defaultcategorydataset.addValue (1.0D, series1, category1); 
  Defaultcategorydataset.addValue (4D, series1, category2); 
  Defaultcategorydataset.addValue (3D, series1, category3); 
  Defaultcategorydataset.addValue (5D, series1, category4); 
  Defaultcategorydataset.addValue (5D, series1, category5); 

  Defaultcategorydataset.addValue (5D, series2, category1); 
  Defaultcategorydataset.addValue (7D, series2, category2); 
  Defaultcategorydataset.addValue (6D, series2, category3); 
  Defaultcategorydataset.addValue (8D, series2, category4); 
  Defaultcategorydataset.addValue (4D, series2, category5); 

  Defaultcategorydataset.addValue (4D, series3, category1); 
  Defaultcategorydataset.addValue (3D, series3, category2); 
  Defaultcategorydataset.addValue (2D, series3, category3); 
  Defaultcategorydataset.addValue (3D, series3, category4); 
  Defaultcategorydataset.addValue (6D, series3, category5); 
  Return defaultcategorydataset; 
  ) 
  2, produced by JFreeChart object ChartFactory 
  Private static JFreeChart createChart (CategoryDataset categorydataset) 
  ( 
  JFreeChart jfreechart = ChartFactory.createBarChart ( "Bar Chart Demo", / / graphics titles 
  "Category", / / domain axis Lable 
  Here is a brief understanding of the good abscissa Lable 
  "Value", / / range axis Lable 
  Yexian here simply for the good ordinate Lable 
  Categorydataset, / / dataset 
  PlotOrientation.VERTICAL, / / vertical display 
  True, / / legend? 
  True, / / tooltips? 
  False); / / URLs? 
  Jfreechart.setBackgroundPaint (Color.white) / / set the background color is white 
  CategoryPlot categoryplot jfreechart.getCategoryPlot = () / / plot: CategoryPlot!    ! 
  Categoryplot.setBackgroundPaint (Color.lightGray); / / chart data show that part of the background color 
  Categoryplot.setDomainGridlinePaint (Color.white); / / abscissa white grid lines 
  Categoryplot.setDomainGridlinesVisible (true); / / visible 
  Categoryplot.setRangeGridlinePaint (Color.white); / / vertical grid of white lines 
  / / Below two longitudinal coordinates of the smallest integer units for the grid 
  NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis (); 
  Numberaxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); 
  BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer (); / / renderer under most of the attention here is modeling 
  To BarRenderer!    ! 
  Barrenderer.setDrawBarOutline (false); / / Bar of the outer contour line is not painted 
  GradientPaint gradientpaint = new GradientPaint (0.0F, 0.0F, Color.blue, 
  0.0F, 0.0F, the new Color (0, 0, 64)) / / set specific colors 
  GradientPaint gradientpaint1 = new GradientPaint (0.0F, 0.0F, Color.green, 
  0.0F, 0.0F, the new Color (0, 64, 0)); 
  GradientPaint gradientpaint2 = new GradientPaint (0.0F, 0.0F, Color.red, 
  0.0F, 0.0F, the new Color (64, 0, 0)); 
  Barrenderer.setSeriesPaint (0, gradientpaint); / / series1 Bar to the above definition of the colour settings 
  Barrenderer.setSeriesPaint (1, gradientpaint1); / / series2 Bar to the above definition of the colour settings 
  Barrenderer.setSeriesPaint (2, gradientpaint2); / / series3 Bar to the above definition of the colour settings 
  Categoryplot.getDomainAxis CategoryAxis categoryaxis = () / / horizontal on the 45-degree tilt Lable 
  Categoryaxis.setCategoryLabelPositions (CategoryLabelPositions.UP_45); 
  Return jfreechart; 
  ) 
  A number of important ways: (a marked increase) 
  IntervalMarker intervalmarker = new IntervalMarker (4.5D and 7.5D); 
  Intervalmarker.setLabel ( "Target Range"); 
  Intervalmarker.setLabelFont (new Font ( "SansSerif", 2, 11)); 
  Intervalmarker.setLabelAnchor (RectangleAnchor.LEFT); 
  Intervalmarker.setLabelTextAnchor (TextAnchor.CENTER_LEFT); 
  Intervalmarker.setPaint (new Color (222, 222, 255, 128)); 
  Categoryplot.addRangeMarker (intervalmarker, Layer.BACKGROUND); 

  4, polyline map 
  Polyline map dataset two CatagoryDataset Interface (concrete realization is the DefaultCategoryDataset), XYDataset Interface 
  1, CatagoryDataset Interface: 
  A, the creation of a data source (dataset): 
  Private static CategoryDataset createDataset () 
  ( 
  String series1 = "First"; 
  String series2 = "Second"; 
  String series3 = "Third"; 
  String type1 = "Type 1"; 
  String type2 = "Type 2"; 
  String type3 = "Type 3"; 
  String type4 = "Type 4"; 
  String type5 = "Type 5"; 
  String type6 = "Type 6"; 
  String type7 = "Type 7"; 
  String type8 = "Type 8"; 
  DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset (); 
  Defaultcategorydataset.addValue (1.0D, series1, type1); 
  Defaultcategorydataset.addValue (4D, series1, type2); 
  Defaultcategorydataset.addValue (3D, series1, type3); 
  Defaultcategorydataset.addValue (5D, series1, type4); 
  Defaultcategorydataset.addValue (5D, series1, type5); 
  Defaultcategorydataset.addValue (7D, series1, type6); 
  Defaultcategorydataset.addValue (7D, series1, type7); 
  Defaultcategorydataset.addValue (8D, series1, type8); 

  Defaultcategorydataset.addValue (5D, series2, type1); 
  Defaultcategorydataset.addValue (7D, series2, type2); 
  Defaultcategorydataset.addValue (6D, series2, type3); 
  Defaultcategorydataset.addValue (8D, series2, type4); 
  Defaultcategorydataset.addValue (4D, series2, type5); 
  Defaultcategorydataset.addValue (4D, series2, type6); 
  Defaultcategorydataset.addValue (2D, series2, type7); 
  Defaultcategorydataset.addValue (1.0D, series2, type8); 

  Defaultcategorydataset.addValue (4D, series3, type1); 
  Defaultcategorydataset.addValue (3D, series3, type2); 
  Defaultcategorydataset.addValue (2D, series3, type3); 
  Defaultcategorydataset.addValue (3D, series3, type4); 
  Defaultcategorydataset.addValue (6D, series3, type5); 
  Defaultcategorydataset.addValue (3D, series3, type6); 
  Defaultcategorydataset.addValue (4D, series3, type7); 
  Defaultcategorydataset.addValue (3D, series3, type8); 
  Return defaultcategorydataset; 
  ) 
  B, produced by ChartFactory JFreeChart object (and some of the above will not repeat the Notes) 
  Private static JFreeChart createChart (CategoryDataset categorydataset) 
  ( 
  JFreeChart jfreechart = ChartFactory.createLineChart ( "Line Chart Demo 1" 
  "Type" 
  "Value" 
  Categorydataset, 
PlotOrientation.VERTICAL,
  True, 
  True, 
  False); 
  Jfreechart.setBackgroundPaint (Color.white); 
  CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot (); 
  Categoryplot.setBackgroundPaint (Color.lightGray); 
  Categoryplot.setRangeGridlinePaint (Color.white); 
  NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis (); 
  Numberaxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); 
  Numberaxis.setAutoRangeIncludesZero (true); 
  / / Renderer under most of the attention here is to shape lineandshaperenderer!    ! 
  LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer (); 
  Lineandshaperenderer.setShapesVisible (true); / / series points (data) that 
  Lineandshaperenderer.setSeriesStroke (0, new BasicStroke (2.0F, 1, 1, 1.0F, the new float [] ( 
  10F, 6F 
  ), 0.0F)); / / definition series "First" (ie series1) of the connection between, here is dotted line, the default is a straight line 
  Lineandshaperenderer.setSeriesStroke (1, new BasicStroke (2.0F, 1, 1, 1.0F, the new float [] ( 
  6F, 6F 
  ), 0.0F)); / / definition series "Second" (ie series2) of the connection between 
  Lineandshaperenderer.setSeriesStroke (2, new BasicStroke (2.0F, 1, 1, 1.0F, the new float [] ( 
  2.0F, 6F 
  ), 0.0F)); / / definition series "Third" (ie series3) of the connection between 
  Return jfreechart; 
  ) 
  A number of important ways: 
  Lineandshaperenderer.setLineVisible (true) / / series points (data) connection between that 
  2, XYDataset Interface: 
  A, the creation of a data source (dataset): 
  Private static XYDataset createDataset () 
  ( 
  XYSeries xyseries = new XYSeries ( "First"); / / object to a XYSeries 
  Xyseries.add (1.0D and 1.0D); 
  Xyseries.add (2D, 4D); 
  Xyseries.add (3D,); 
  Xyseries.add (4D, 5D); 
  Xyseries.add (5D, 5D); 
  Xyseries.add (6D, 7D); 
  Xyseries.add (7D, 7D); 
  Xyseries.add (8D, 8D); 

  XYSeries xyseries1 = new XYSeries ( "Second"); 
  Xyseries1.add (1.0D, 5D); 
  Xyseries1.add (2D, 7D); 
  Xyseries1.add (3D, 6D); 
  Xyseries1.add (4D, 8D); 
  Xyseries1.add (5D, 4D); 
  Xyseries1.add (6D, 4D); 
  Xyseries1.add (7D, 2D); 
  Xyseries1.add (8D, 1.0D); 

  XYSeries xyseries2 = new XYSeries ( "Third"); 
  Xyseries2.add (3D, 4D); 
  Xyseries2.add (4D, 3D); 
  Xyseries2.add (5D, 2D); 
  Xyseries2.add (6D, 3D); 
  Xyseries2.add (7D, 6D); 
  Xyseries2.add (8D, 3D); 
  Xyseries2.add (9D, 4D); 
  Xyseries2.add (10D, 3D); 

  XYSeriesCollection xyseriescollection = new XYSeriesCollection (); / / reuse targets XYSeriesCollection added to the XYSeries 
  Xyseriescollection.addSeries (xyseries); 
  Xyseriescollection.addSeries (xyseries1); 
  Xyseriescollection.addSeries (xyseries2); 
  Return xyseriescollection; 
  ) 
  B, produced by JFreeChart object ChartFactory 
  Private static JFreeChart createChart (XYDataset xydataset) 
  ( 
  JFreeChart jfreechart = ChartFactory.createXYLineChart ( "Line Chart Demo 2" 
  "X" 
  "Y" 
  Xydataset, 
PlotOrientation.VERTICAL,
  True, 
  True, 
  False); 
  Jfreechart.setBackgroundPaint (Color.white); 
  XYPlot xyplot = (XYPlot) jfreechart.getPlot (); / / plot: XYPlot!    ! 
  Xyplot.setBackgroundPaint (Color.lightGray); / / chart data show that part of the background color 
  Xyplot.setAxisOffset (new RectangleInsets (5D, 5D, 5D, 5D)); / / coordinate axis and chart data showed some distance 
  Xyplot.setDomainGridlinePaint (Color.white); / / grid lines color 
  Xyplot.setRangeGridlinePaint (Color.white); 
  / / Renderer XYLineAndShapeRenderer attention here!    ! 
  XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer (); 
  Xylineandshaperenderer.setShapesVisible (true); / / data points that 
  Xylineandshaperenderer.setShapesFilled (true); / / data points have been filled in the hollow point is not that 
  NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis (); 
  Numberaxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); 
  Return jfreechart; 
  ) 
  A number of important ways: 
  XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer (); 
  Xylineandshaperenderer.setSeriesLinesVisible (0, false); / / XYSeries a connection between the data points not visible 
  Xylineandshaperenderer.setSeriesShapesVisible (1, false); / / second data point not visible XYSeries 
  Xyplot.setRenderer (xylineandshaperenderer); 

  5, the time sequence diagrams 
  Polyline time sequence diagrams and plans are similar, it is different in the domain of the data-axis and time is not just numbers.    Time series dataset is the plan 
  XYDataset interface, the specific category is TimeSeriesCollection achieve, and above similar, TimeSeries object, which has been inserted into the 
  TimeSeriesCollection. 
  1, the creation of a data source (dataset): 
  Private static XYDataset createDataset () 
  ( 
  TimeSeries timeseries = new TimeSeries ( "L & G European Index Trust," Month.class); 
  Timeseries.add (new Month (2, 2001), 181.8D); / / Month.class here is using the same also Day.class Year.class etc. 
  Timeseries.add (new Month (3, 2001), 167.3D); 
  Timeseries.add (new Month (4, 2001), 153.8D); 
  Timeseries.add (new Month (5, 2001), 167.6D); 
  Timeseries.add (new Month (6, 2001), 158.8D); 
  Timeseries.add (new Month (7, 2001), 148.3D); 
  Timeseries.add (new Month (8, 2001), 153.9D); 
  Timeseries.add (new Month (September, 2001), 142.7D); 
  Timeseries.add (new Month (10, 2001), 123.2D); 
  Timeseries.add (new Month (November, 2001), 131.8D); 
  Timeseries.add (new Month (12, 2001), 139.6D); 
  Timeseries.add (new Month (1, 2002), 142.9D); 
  Timeseries.add (new Month (2, 2002), 138.7D); 
  Timeseries.add (new Month (3, 2002), 137.3D); 
  Timeseries.add (new Month (4, 2002), 143.9D); 
  Timeseries.add (new Month (5, 2002), 139.8D); 
  Timeseries.add (new Month (6, 2002), 137D); 
  Timeseries.add (new Month (7, 2002), 132.8D); 

  TimeSeries timeseries1 = new TimeSeries ( "L & G UK Index Trust," Month.class); 
  Timeseries1.add (new Month (2, 2001), 129.6D); 
  Timeseries1.add (new Month (3, 2001), 123.2D); 
  Timeseries1.add (new Month (4, 2001), 117.2D); 
  Timeseries1.add (new Month (5, 2001), 124.1D); 
  Timeseries1.add (new Month (6, 2001), 122.6D); 
  Timeseries1.add (new Month (7, 2001), 119.2D); 
  Timeseries1.add (new Month (8, 2001), 116.5D); 
  Timeseries1.add (new Month (September, 2001), 112.7D); 
  Timeseries1.add (new Month (10, 2001), 101.5D); 
  Timeseries1.add (new Month (November, 2001), 106.1D); 
  Timeseries1.add (new Month (12, 2001), 110.3D); 
  Timeseries1.add (new Month (1, 2002), 111.7D); 
  Timeseries1.add (new Month (2, 2002), 111D); 
  Timeseries1.add (new Month (3, 2002), 109.6D); 
  Timeseries1.add (new Month (4, 2002), 113.2D); 
  Timeseries1.add (new Month (5, 2002), 111.6D); 
  Timeseries1.add (new Month (6, 2002), 108.8D); 
  Timeseries1.add (new Month (7, 2002), 101.6D); 
  TimeSeriesCollection timeseriescollection = new TimeSeriesCollection (); 
  Timeseriescollection.addSeries (timeseries); 
  Timeseriescollection.addSeries (timeseries1); 
  Timeseriescollection.setDomainIsPointsInTime (true); / / domain axis calibration point represents the point in time rather than time 
  Return timeseriescollection; 
  ) 
  2, produced by JFreeChart object ChartFactory 
  Private static JFreeChart createChart (XYDataset xydataset) 
  ( 
  JFreeChart jfreechart = ChartFactory.createTimeSeriesChart ( "Legal & General Unit Trust Prices." 
  "Date" 
  "Price Per Unit" 
  Xydataset, 
  True, 
  True, 
  False); 
  Jfreechart.setBackgroundPaint (Color.white); 
  XYPlot xyplot = (XYPlot) jfreechart.getPlot (); / / plot: XYPlot! 
  Xyplot.setBackgroundPaint (Color.lightGray); 
  Xyplot.setDomainGridlinePaint (Color.white); 
  Xyplot.setRangeGridlinePaint (Color.white); 
  Xyplot.setAxisOffset (new RectangleInsets (5D, 5D, 5D, 5D)); 
  Xyplot.setDomainCrosshairVisible (true); 
  Xyplot.setRangeCrosshairVisible (true); 
  Org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer (); 
  If (xyitemrenderer instanceof XYLineAndShapeRenderer) 
  ( 
  XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; 
  Xylineandshaperenderer.setDefaultShapesVisible (true); / / data points that 
  Xylineandshaperenderer.setDefaultShapesFilled (true); / / data points is a solid point 
  ) 
  DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis (); / / date display axis of the domain definition format 
  Dateaxis.setDateFormatOverride (new SimpleDateFormat ( "MMM-yyyy")); 
  Return jfreechart; 
  ) 
  A number of important ways: 
  A increase marker: 
  Xyplot.addRangeMarker (new ValueMarker (550D)); / / numerical axis 
  New Quarter Quarter quarter = (2, 2002); 
  Xyplot.addDomainMarker (new ValueMarker (quarter.getMiddleMillisecond ())); / / Timelines 
  B, the adjustment of data points 
  XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer (); 
  Xylineandshaperenderer.setDefaultShapesVisible (true); / / data points that 
  Xylineandshaperenderer.setSeriesFillPaint (0, Color.red); / / fill data points for the red 
  Xylineandshaperenderer.setSeriesFillPaint (1, Color.white); / / fill data points for the white 
  Xylineandshaperenderer.setUseFillPaint (true); / / Applications 
  C, average curve 
  This curve is what is the use?    Very simple example, there is a day for six months of data from the units curve, we would like to see on the data units 
  Change, then we can use it. 
  TimeSeries timeseries createEURTimeSeries = () / / is a day for six months to the data units 
  TimeSeries timeseries1 = MovingAverage.createMovingAverage (timeseries, 
  "30 day moving average." 
  30, / / a 30 day cycle 
  30); / / The first 30 days of Skip 
  TimeSeriesCollection timeseriescollection = new TimeSeriesCollection (); 
  Timeseriescollection.addSeries (timeseries); 
  Timeseriescollection.addSeries (timeseries1); 
  Return timeseriescollection; 

  6, summing up 
  Dataset plot renderer 
  Bingtu PieDataset (DefaultPieDataset) PiePlot —— 
  Bar CatagoryDataset (DefaultCategoryDataset) CategoryPlot BarRenderer 
  Polyline plans CatagoryDataset (DefaultCategoryDataset) CategoryPlot LineAndShapeRenderer 
  XYDataset (XYSeriesCollection) XYPlot XYLineAndShapeRenderer 
  XYDataset time sequence diagram (TimeSeriesCollection) XYPlot XYLineAndShapeRenderer 
  Here is some commonly used method, or look at specific API (to be continued [:)]) 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Recommend Articles

Comments

Leave a Reply