View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.chart;
2   
3   /*
4    * Copyright 2006 David Vicente
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  
20  import java.awt.Font;
21  import java.awt.Paint;
22  
23  import org.jfree.chart.ChartFactory;
24  import org.jfree.chart.plot.PiePlot;
25  import org.jfree.data.general.PieDataset;
26  import org.jfree.util.Rotation;
27  
28  /**
29   * 
30   * @author <a href="dvicente72@gmail.com">David Vicente</a>
31   * 
32   */
33  public class PieChartRenderer extends AbstractChartRenderer
34  {
35      /**
36       * 
37       */
38      private static final int FONT_SIZE = 10;
39      /**
40       * 
41       */
42      private static final double INTERIOR_GAP = 0.33D;
43      /**
44       * 
45       */
46      private static final double LABEL_GAP = 0.02D;
47      /**
48       * 
49       */
50      private static final double START_ANGLE = 45D;
51  
52      /**
53       * 
54       * @param dashboardReport
55       * @param strategy
56       */
57      public PieChartRenderer( IChartStrategy strategy )
58      {
59          super( strategy );
60      }
61  
62      /**
63       * 
64       * @param dashboardReport
65       * @param strategy
66       * @param width
67       * @param height
68       */
69      public PieChartRenderer( IChartStrategy strategy,
70                               int width, int height )
71      {
72          super( strategy, width, height );
73      }
74      
75      /* (non-Javadoc)
76       * @see org.codehaus.mojo.dashboard.report.plugin.chart.AbstractChartRenderer#createChart()
77       */
78      public void createChart()
79      {
80  
81          PieDataset dataset = (PieDataset) this.datasetStrategy.getDataset();
82          report = ChartFactory.createPieChart( this.datasetStrategy.getTitle(), dataset, true, true, false );
83          PiePlot plot = (PiePlot) report.getPlot();
84          plot.setCircular( false );
85          plot.setDirection( Rotation.ANTICLOCKWISE );
86          /*
87           * plot.setExplodePercent(0, 0.15D); plot.setExplodePercent(1, 0.15D);
88           */
89          plot.setInteriorGap( PieChartRenderer.INTERIOR_GAP );
90          plot.setLabelFont( new Font("Lucida", 0, PieChartRenderer.FONT_SIZE ) );
91          plot.setLabelGap( PieChartRenderer.LABEL_GAP );
92          plot.setNoDataMessage( "No data available" );
93          plot.setStartAngle( PieChartRenderer.START_ANGLE );
94          Paint[] paints = this.datasetStrategy.getPaintColor();
95  
96          for ( int i = 0; i < dataset.getItemCount() && i < paints.length; i++ )
97          {
98              plot.setSectionPaint( i, paints[i] );
99          }
100     }
101 }