-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-1graph.html
120 lines (116 loc) · 3.1 KB
/
1-1graph.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title:{
text: "機車與電動機車的補助金額差異"
},
axisY: {
title: "NT$",
},
axisX: {
interval: 1,
},
legend: {
cursor:"pointer",
itemclick : toggleDataSeries
},
toolTip: {
shared: true,
content: toolTipFormatter
},
data: [{
type: "bar",
showInLegend: true,
name: "價格",
color: "gold",
dataPoints: [
{ y: 84200, label: "Racing S 125" },
{ y: 84000, label: "Jet S 125" },
{ y: 83700, label: "勁戰 125" },
{ y: 85000, label: "Alpha Max 125" },
{ y: 59000, label: "GP 125" },
{ y: 59000, label: "GT Super 2" },
{ y: 65500, label: "新迪爵 125" },
{ y: 69700, label: "勁豪 125"},
{ y: 73800, label: "Gogoro 2"},
{ y: 79800, label: "Gogoro 2 Plus"},
{ y: 129000, label: "Gogoro S1"},
{ y: 95800, label: "Gogoro S2"}
]
},
{
type: "bar",
showInLegend: true,
name: "平均補助",
color: "grey",
dataPoints: [
{ y: 2050, label: "Racing S 125" },
{ y: 2050, label: "Jet S 125" },
{ y: 2050, label: "勁戰 125" },
{ y: 2050, label: "Alpha Max 125" },
{ y: 2050, label: "GP 125" },
{ y: 2050, label: "GT Super 2" },
{ y: 2050, label: "新迪爵 125" },
{ y: 2050, label: "勁豪 125"},
{ y: 24500, label: "Gogoro 2"},
{ y: 24500, label: "Gogoro 2 Plus"},
{ y: 24500, label: "Gogoro S1"},
{ y: 24500, label: "Gogoro S2"},
]
},
{
type: "bar",
showInLegend: true,
name: "實際購買價格",
color: "#A57164",
dataPoints: [
{ y: 82150, label: "Racing S 125" },
{ y: 81950, label: "Jet S 125" },
{ y: 81650, label: "勁戰 125" },
{ y: 82950, label: "Alpha Max 125" },
{ y: 56950, label: "GP 125" },
{ y: 56950, label: "GT Super 2" },
{ y: 63450, label: "新迪爵 125" },
{ y: 67650, label: "勁豪 125"},
{ y: 49300, label: "Gogoro 2"},
{ y: 55300, label: "Gogoro 2 Plus"},
{ y: 104500, label: "Gogoro S1"},
{ y: 71300, label: "Gogoro S2"},
]
}]
});
chart.render();
function toolTipFormatter(e) {
var str = "";
var total = 0 ;
var str3;
var str2 ;
for (var i = 0; i < e.entries.length; i++){
var str1 = "<span style= \"color:"+e.entries[i].dataSeries.color + "\">" + e.entries[i].dataSeries.name + "</span>: <strong>"+ e.entries[i].dataPoint.y + "</strong> <br/>" ;
str = str.concat(str1);
}
str2 = "<strong>" + e.entries[0].dataPoint.label + "</strong> <br/>";
str3 = "<span style = \"color:Tomato\"></span><strong>" + "</strong><br/>";
return (str2.concat(str)).concat(str3);
}
function toggleDataSeries(e) {
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
}
else {
e.dataSeries.visible = true;
}
chart.render();
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 500px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>