-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathechart.html
More file actions
82 lines (68 loc) · 2.44 KB
/
echart.html
File metadata and controls
82 lines (68 loc) · 2.44 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.7.0/echarts.js"></script>
</head>
<body onload="execute()">
<h1>Bar Chart</h1>
<div id="sampleBarChart" style="width:800px;height:500px;"></div>
<h1>Lines Chart</h1>
<div id="linesChart" style="width:1200px;height:500px;"></div>
</body>
<script>
var sampleBarChart = echarts.init( document.getElementById('sampleBarChart'));
var option = {
title: {
text: 'Sample Bar Chart'
},
xAxis: {
data: [1, 2, 3, 4, 5]
},
yAxis: {},
series: [{
type: 'bar',
data: [1, 2, 4, 8, 16]
}]
};
// use configuration item and data specified to show chart
sampleBarChart.setOption(option);
function csvToColumnArrays(csv) {
var mainObj = {},
header = Object.keys(csv[0]);
for (var i = 0; i < header.length; i++) { mainObj[header[i]]=[]; };
csv.map(function(d) { for (key in mainObj) { mainObj[key].push(d[key]) } });
return mainObj;
}
var data2014Top100;
function execute() {
// nesting of calls avoids asynchronous loading issues. probably better ways now in JS
d3.csv("timesData2014Top100.csv").then( function(csv) {
data2014Top100 = csvToColumnArrays(csv);
createLineChart();
});
}
function createLineChart() {
var lineChart = echarts.init( document.getElementById('linesChart'));
var option = {
title: {
text: 'Citation and Teaching vs World Rank of Top 100 Universities'
},
xAxis: {
data: data2014Top100.world_rank,
boundaryGap: false
},
legend: { orient: 'vertical',
data:['Citations', 'Teaching']
},
yAxis: { type: 'value'},
series: [{ name: 'Citations', type: 'line', data: data2014Top100.citations },
{ name: 'Teaching', type: 'line', data: data2014Top100.teaching, showSymbol: false }
]
};
// use configuration item and data specified to show chart
lineChart.setOption(option);
}
</script>
</html>