-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo-linechart.html
54 lines (45 loc) · 1.39 KB
/
demo-linechart.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3LineChart</title>
<meta name="description" content="Demo example of D3LineChart">
<meta name="author" content="Matous Havlena (@matoushavlena)">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<link rel="stylesheet" href="./css/d3.linechart.css">
<script src="./js/d3.core.js" charset="utf-8"></script>
<script src="./js/d3.linechart.js" charset="utf-8"></script>
</head>
<body>
<div id="linechart"></div>
<button id="button">Generate Random Dataset</button>
<script type="text/javascript">
$(document).ready(function() {
var linechart = new D3LineChart({
container: "#linechart"
});
linechart.show();
$("#button").on("click", function() {
var newData = new Array();
var year = getRandomInt(2005, 2014);
var numCategories = getRandomInt(1, 10);
for (var i=0; i<numCategories; i++) {
var category = {};
category.key = "category "+i;
category.values = new Array();
for (var j=year; j<=2015; j++) {
category.values.push({ x: j, y: getRandomInt(-50, 50) });
};
newData.push(category);
}
linechart.dataset = newData;
linechart.update();
});
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
});
</script>
</body>
</html>