commit | author | age
|
44bbc4
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
package com.gitblit.wicket.charting;
|
|
17 |
|
|
18 |
import java.text.MessageFormat;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Builds an interactive line chart using the Visualization API.
|
|
22 |
*
|
|
23 |
* @author James Moger
|
|
24 |
*
|
|
25 |
*/
|
|
26 |
public class GoogleLineChart extends GoogleChart {
|
|
27 |
|
|
28 |
private static final long serialVersionUID = 1L;
|
|
29 |
|
|
30 |
public GoogleLineChart(String tagId, String title, String keyName, String valueName) {
|
|
31 |
super(tagId, title, keyName, valueName);
|
|
32 |
}
|
|
33 |
|
|
34 |
@Override
|
|
35 |
protected void appendChart(StringBuilder sb) {
|
|
36 |
String dName = "data_" + dataName;
|
|
37 |
line(sb, MessageFormat.format("var {0} = new google.visualization.DataTable();", dName));
|
|
38 |
line(sb, MessageFormat.format("{0}.addColumn(''string'', ''{1}'');", dName, keyName));
|
|
39 |
line(sb, MessageFormat.format("{0}.addColumn(''number'', ''{1}'');", dName, valueName));
|
|
40 |
line(sb, MessageFormat.format("{0}.addRows({1,number,0});", dName, values.size()));
|
|
41 |
|
|
42 |
for (int i = 0; i < values.size(); i++) {
|
|
43 |
ChartValue value = values.get(i);
|
|
44 |
line(sb, MessageFormat.format("{0}.setValue({1,number,0}, 0, ''{2}'');", dName, i,
|
|
45 |
value.name));
|
|
46 |
line(sb, MessageFormat.format("{0}.setValue({1,number,0}, 1, {2,number,0.0});", dName,
|
|
47 |
i, value.value));
|
|
48 |
}
|
|
49 |
|
|
50 |
String cName = "chart_" + dataName;
|
|
51 |
line(sb, MessageFormat.format(
|
|
52 |
"var {0} = new google.visualization.LineChart(document.getElementById(''{1}''));",
|
|
53 |
cName, tagId));
|
|
54 |
line(sb,
|
|
55 |
MessageFormat
|
e69358
|
56 |
.format("{0}.draw({1}, '{'width: {2,number,0}, height: {3,number,0}, pointSize: 4, chartArea:'{'left:20,top:20'}', vAxis: '{' textPosition: ''none'' '}', legend: ''none'', title: ''{4}'' '}');",
|
44bbc4
|
57 |
cName, dName, width, height, title));
|
JM |
58 |
line(sb, "");
|
|
59 |
}
|
|
60 |
} |