| 23 |
liveuser |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
|
2 |
<html>
|
|
|
3 |
|
|
|
4 |
<head>
|
|
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
6 |
<title>amCharts examples</title>
|
|
|
7 |
<link rel="stylesheet" href="style.css" type="text/css">
|
|
|
8 |
<script src="../amcharts/amcharts.js" type="text/javascript"></script>
|
|
|
9 |
<script src="../amcharts/serial.js" type="text/javascript"></script>
|
|
|
10 |
|
|
|
11 |
<script>
|
|
|
12 |
var chart;
|
|
|
13 |
var chartData = [];
|
|
|
14 |
|
|
|
15 |
AmCharts.ready(function () {
|
|
|
16 |
// generate some random data first
|
|
|
17 |
generateChartData();
|
|
|
18 |
|
|
|
19 |
// SERIAL CHART
|
|
|
20 |
chart = new AmCharts.AmSerialChart();
|
|
|
21 |
|
|
|
22 |
chart.dataProvider = chartData;
|
|
|
23 |
chart.categoryField = "date";
|
|
|
24 |
|
|
|
25 |
// listen for "dataUpdated" event (fired when chart is inited) and call zoomChart method when it happens
|
|
|
26 |
chart.addListener("dataUpdated", zoomChart);
|
|
|
27 |
|
|
|
28 |
// AXES
|
|
|
29 |
// category
|
|
|
30 |
var categoryAxis = chart.categoryAxis;
|
|
|
31 |
categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
|
|
|
32 |
categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
|
|
|
33 |
categoryAxis.minorGridEnabled = true;
|
|
|
34 |
categoryAxis.axisColor = "#DADADA";
|
|
|
35 |
categoryAxis.twoLineMode = true;
|
|
|
36 |
categoryAxis.dateFormats = [{
|
|
|
37 |
period: 'fff',
|
|
|
38 |
format: 'JJ:NN:SS'
|
|
|
39 |
}, {
|
|
|
40 |
period: 'ss',
|
|
|
41 |
format: 'JJ:NN:SS'
|
|
|
42 |
}, {
|
|
|
43 |
period: 'mm',
|
|
|
44 |
format: 'JJ:NN'
|
|
|
45 |
}, {
|
|
|
46 |
period: 'hh',
|
|
|
47 |
format: 'JJ:NN'
|
|
|
48 |
}, {
|
|
|
49 |
period: 'DD',
|
|
|
50 |
format: 'DD'
|
|
|
51 |
}, {
|
|
|
52 |
period: 'WW',
|
|
|
53 |
format: 'DD'
|
|
|
54 |
}, {
|
|
|
55 |
period: 'MM',
|
|
|
56 |
format: 'MMM'
|
|
|
57 |
}, {
|
|
|
58 |
period: 'YYYY',
|
|
|
59 |
format: 'YYYY'
|
|
|
60 |
}];
|
|
|
61 |
|
|
|
62 |
// first value axis (on the left)
|
|
|
63 |
var valueAxis1 = new AmCharts.ValueAxis();
|
|
|
64 |
valueAxis1.axisColor = "#FF6600";
|
|
|
65 |
valueAxis1.axisThickness = 2;
|
|
|
66 |
valueAxis1.gridAlpha = 0;
|
|
|
67 |
chart.addValueAxis(valueAxis1);
|
|
|
68 |
|
|
|
69 |
// second value axis (on the right)
|
|
|
70 |
var valueAxis2 = new AmCharts.ValueAxis();
|
|
|
71 |
valueAxis2.position = "right"; // this line makes the axis to appear on the right
|
|
|
72 |
valueAxis2.axisColor = "#FCD202";
|
|
|
73 |
valueAxis2.gridAlpha = 0;
|
|
|
74 |
valueAxis2.axisThickness = 2;
|
|
|
75 |
chart.addValueAxis(valueAxis2);
|
|
|
76 |
|
|
|
77 |
// third value axis (on the left, detached)
|
|
|
78 |
valueAxis3 = new AmCharts.ValueAxis();
|
|
|
79 |
valueAxis3.offset = 50; // this line makes the axis to appear detached from plot area
|
|
|
80 |
valueAxis3.gridAlpha = 0;
|
|
|
81 |
valueAxis3.axisColor = "#B0DE09";
|
|
|
82 |
valueAxis3.axisThickness = 2;
|
|
|
83 |
chart.addValueAxis(valueAxis3);
|
|
|
84 |
|
|
|
85 |
// GRAPHS
|
|
|
86 |
// first graph
|
|
|
87 |
var graph1 = new AmCharts.AmGraph();
|
|
|
88 |
graph1.valueAxis = valueAxis1; // we have to indicate which value axis should be used
|
|
|
89 |
graph1.title = "red line";
|
|
|
90 |
graph1.valueField = "visits";
|
|
|
91 |
graph1.bullet = "round";
|
|
|
92 |
graph1.hideBulletsCount = 30;
|
|
|
93 |
graph1.bulletBorderThickness = 1;
|
|
|
94 |
chart.addGraph(graph1);
|
|
|
95 |
|
|
|
96 |
// second graph
|
|
|
97 |
var graph2 = new AmCharts.AmGraph();
|
|
|
98 |
graph2.valueAxis = valueAxis2; // we have to indicate which value axis should be used
|
|
|
99 |
graph2.title = "yellow line";
|
|
|
100 |
graph2.valueField = "hits";
|
|
|
101 |
graph2.bullet = "square";
|
|
|
102 |
graph2.hideBulletsCount = 30;
|
|
|
103 |
graph2.bulletBorderThickness = 1;
|
|
|
104 |
chart.addGraph(graph2);
|
|
|
105 |
|
|
|
106 |
// third graph
|
|
|
107 |
var graph3 = new AmCharts.AmGraph();
|
|
|
108 |
graph3.valueAxis = valueAxis3; // we have to indicate which value axis should be used
|
|
|
109 |
graph3.valueField = "views";
|
|
|
110 |
graph3.title = "green line";
|
|
|
111 |
graph3.bullet = "triangleUp";
|
|
|
112 |
graph3.hideBulletsCount = 30;
|
|
|
113 |
graph3.bulletBorderThickness = 1;
|
|
|
114 |
chart.addGraph(graph3);
|
|
|
115 |
|
|
|
116 |
// CURSOR
|
|
|
117 |
var chartCursor = new AmCharts.ChartCursor();
|
|
|
118 |
chartCursor.cursorAlpha = 0.1;
|
|
|
119 |
chartCursor.fullWidth = true;
|
|
|
120 |
chartCursor.valueLineBalloonEnabled = true;
|
|
|
121 |
chart.addChartCursor(chartCursor);
|
|
|
122 |
|
|
|
123 |
// SCROLLBAR
|
|
|
124 |
var chartScrollbar = new AmCharts.ChartScrollbar();
|
|
|
125 |
chart.addChartScrollbar(chartScrollbar);
|
|
|
126 |
|
|
|
127 |
// LEGEND
|
|
|
128 |
var legend = new AmCharts.AmLegend();
|
|
|
129 |
legend.marginLeft = 110;
|
|
|
130 |
legend.useGraphSettings = true;
|
|
|
131 |
chart.addLegend(legend);
|
|
|
132 |
|
|
|
133 |
// WRITE
|
|
|
134 |
chart.write("chartdiv");
|
|
|
135 |
});
|
|
|
136 |
|
|
|
137 |
// generate some random data, quite different range
|
|
|
138 |
function generateChartData() {
|
|
|
139 |
var firstDate = new Date();
|
|
|
140 |
firstDate.setDate(firstDate.getDate() - 50);
|
|
|
141 |
|
|
|
142 |
for (var i = 0; i < 50; i++) {
|
|
|
143 |
// we create date objects here. In your data, you can have date strings
|
|
|
144 |
// and then set format of your dates using chart.dataDateFormat property,
|
|
|
145 |
// however when possible, use date objects, as this will speed up chart rendering.
|
|
|
146 |
var newDate = new Date(firstDate);
|
|
|
147 |
newDate.setDate(newDate.getDate() + i);
|
|
|
148 |
|
|
|
149 |
var visits = Math.round(Math.random() * 40) + 100;
|
|
|
150 |
var hits = Math.round(Math.random() * 80) + 500;
|
|
|
151 |
var views = Math.round(Math.random() * 6000);
|
|
|
152 |
|
|
|
153 |
chartData.push({
|
|
|
154 |
date: newDate,
|
|
|
155 |
visits: visits,
|
|
|
156 |
hits: hits,
|
|
|
157 |
views: views
|
|
|
158 |
});
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
// this method is called when chart is first inited as we listen for "dataUpdated" event
|
|
|
163 |
function zoomChart() {
|
|
|
164 |
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
|
|
|
165 |
chart.zoomToIndexes(10, 20);
|
|
|
166 |
}
|
|
|
167 |
</script>
|
|
|
168 |
</head>
|
|
|
169 |
|
|
|
170 |
<body>
|
|
|
171 |
<div id="chartdiv" style="width: 100%; height: 400px;"></div>
|
|
|
172 |
</body>
|
|
|
173 |
|
|
|
174 |
</html>
|