1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.statcvs.output;
21
22 import java.awt.Dimension;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import net.sf.statcvs.Messages;
27 import net.sf.statcvs.charts.ChartImage;
28
29 import org.jfree.chart.ChartFactory;
30 import org.jfree.chart.JFreeChart;
31 import org.jfree.chart.annotations.XYAnnotation;
32 import org.jfree.chart.axis.DateAxis;
33 import org.jfree.chart.axis.NumberAxis;
34 import org.jfree.chart.plot.PlotOrientation;
35 import org.jfree.chart.plot.XYPlot;
36 import org.jfree.chart.renderer.xy.XYBarRenderer;
37 import org.jfree.chart.renderer.xy.XYStepRenderer;
38 import org.jfree.data.time.TimeSeries;
39 import org.jfree.data.time.TimeSeriesCollection;
40 import org.jfree.data.xy.IntervalXYDataset;
41
42
43
44
45
46
47 public class LOCChurnChartMaker {
48 private static final double LOWER_MARGIN = 0.40;
49 private ChartImage chartFile = null;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public LOCChurnChartMaker(final ReportConfig config, final TimeSeries churnSeries, final TimeSeries locSeries, final String title, final String fileName,
70 final Dimension size, final List annotations) {
71 final TimeSeriesCollection collection = new TimeSeriesCollection(locSeries);
72
73 final TimeSeriesCollection churnCollection = new TimeSeriesCollection(churnSeries);
74
75 final JFreeChart chart = createChart(collection, churnCollection, title, annotations);
76
77 chartFile = config.createChartImage(fileName, title, chart, size);
78 }
79
80 public ChartImage toFile() {
81 return this.chartFile;
82 }
83
84 private JFreeChart createChart(final TimeSeriesCollection locCollection, final TimeSeriesCollection churnSet, final String title, final List annotations) {
85 final String domain = Messages.getString("TIME_LOC_DOMAIN");
86 final String range = Messages.getString("TIME_LOC_RANGE");
87
88 final IntervalXYDataset data = locCollection;
89 final boolean legend = true;
90
91 final JFreeChart chart = ChartFactory.createXYBarChart(ConfigurationOptions.getProjectName() + ":" + title, domain, true, range, data,
92 PlotOrientation.VERTICAL, legend, false, false);
93
94 final XYPlot plot = chart.getXYPlot();
95 plot.setRenderer(new XYStepRenderer());
96
97
98 final NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
99 rangeAxis1.setLowerMargin(LOWER_MARGIN);
100
101 final DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
102 domainAxis.setVerticalTickLabels(true);
103
104
105 final NumberAxis rangeAxis2 = new NumberAxis(Messages.getString("CHURN_RANGE"));
106 rangeAxis2.setUpperMargin(1.00);
107 plot.setRangeAxis(1, rangeAxis2);
108 plot.setDataset(1, churnSet);
109 plot.setRangeAxis(1, rangeAxis2);
110 plot.mapDatasetToRangeAxis(1, 1);
111 final XYBarRenderer renderer2 = new XYBarRenderer(0.20);
112 plot.setRenderer(1, renderer2);
113
114 if (annotations != null) {
115 for (final Iterator it = annotations.iterator(); it.hasNext();) {
116 plot.addAnnotation((XYAnnotation) it.next());
117 }
118 }
119
120 return chart;
121 }
122 }