01: /*
02: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.ubt.report.view.chart;
06:
07: import com.sun.portal.ubt.report.data.DataMiner;
08: import com.sun.portal.ubt.report.data.file.raw.ChannelRenderMiner;
09: import com.sun.portal.ubt.report.data.file.aggregate.ChannelRenderMinerAggregator;
10: import com.sun.portal.ubt.report.view.IllegalMinerException;
11: import com.sun.portal.ubt.report.util.UBTReportResourceBundle;
12: import org.jfree.chart.JFreeChart;
13: import org.jfree.chart.ChartFactory;
14: import org.jfree.chart.plot.PlotOrientation;
15: import org.jfree.data.category.CategoryDataset;
16: import org.jfree.data.category.DefaultIntervalCategoryDataset;
17:
18: import java.util.*;
19:
20: /**
21: *
22: */
23: public class ChannelRenderUniqueUsersChart {
24: private DataMiner miner;
25: public static final String XAxisLabel = "Channels";
26: public static final String YAxisLabel = "NoUsers";
27: public static final String ChannelPopularityUnique = "ChannelPopularityUnique";
28: private UBTReportResourceBundle reportsResource;
29:
30: public ChannelRenderUniqueUsersChart(DataMiner miner, Locale locale)
31: throws IllegalMinerException {
32: if (!((miner instanceof ChannelRenderMiner || miner instanceof ChannelRenderMinerAggregator)))
33: throw new IllegalMinerException();
34: this .miner = miner;
35: reportsResource = new UBTReportResourceBundle(locale);
36: }
37:
38: private JFreeChart createChart(String container) {
39: CategoryDataset dataset = createDataSet(container);
40: JFreeChart chart = ChartFactory.createBarChart(reportsResource
41: .getReportProperty(ChannelPopularityUnique)
42: + " " + container, reportsResource
43: .getReportProperty(XAxisLabel), // X-Axis label
44: reportsResource.getReportProperty(YAxisLabel), // Y-Axis label
45: dataset, // Dataset
46: PlotOrientation.VERTICAL,// Orientation
47: true, false, false // Show legend
48: );
49: UBTChartUtil.customizeChart(chart);
50: return chart;
51: }
52:
53: private CategoryDataset createDataSet(String container) {
54: TreeMap data = (TreeMap) ((TreeMap) miner.getData())
55: .get(container);
56: String[] channels; //channels
57: String[] users = { "" };
58: Number[][] startValues;
59: Object[] objcArray = (Object[]) (data).keySet().toArray();
60: channels = new String[objcArray.length];
61: copy(objcArray, channels);
62: startValues = new Number[channels.length][1];
63: for (int i = 0; i < startValues.length; i++) {
64: Arrays.fill(startValues[i], new Integer(0));
65: }
66: for (int i = 0; i < channels.length; i++) {
67: startValues[i][0] = new Integer(((TreeMap) data
68: .get(channels[i])).size());
69: }
70: return new DefaultIntervalCategoryDataset(channels, users,
71: startValues, startValues);
72: }
73:
74: private void copy(Object[] objArray, String[] series) {
75: for (int i = 0; i < objArray.length; i++) {
76: series[i] = (String) objArray[i];
77: }
78: }
79:
80: public Vector getChart() {
81: TreeMap data = (TreeMap) miner.getData();
82: Vector containers = new Vector();
83: int j = 0;
84: Iterator containerI = data.keySet().iterator();
85: while (containerI.hasNext()) {
86: containers.add(j, containerI.next());
87: j++;
88: }
89: Vector charts = new Vector(containers.size());
90: for (int k = 0; k < containers.size(); k++) {
91: charts.add(k, new UBTChartRenderer(
92: createChart((String) containers.get(k))));
93: }
94: return charts;
95: }
96: }
|