1 package org.codehaus.mojo.dashboard.report.plugin.chart;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
55
56
57 public PieChartRenderer( IChartStrategy strategy )
58 {
59 super( strategy );
60 }
61
62
63
64
65
66
67
68
69 public PieChartRenderer( IChartStrategy strategy,
70 int width, int height )
71 {
72 super( strategy, width, height );
73 }
74
75
76
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
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 }