-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart.js
84 lines (71 loc) · 2.87 KB
/
chart.js
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
function chart(dynamic,kind)
{
var chartAttrs = {
"width": '100%',
"height": '90%'
};
var chartMargins = {
right: 75
};
var willShowControls = false;
var willHaveGuidelines = false;
var willBeInteractive = false;
var willUseVoronoi = false;
var yLabel = 'Mass of Waste (Tonnes)';
var yMax = 400000;
var json_data1 = 'raw-data-run5-waste.json';
var json_data2 = 'raw-data-run3-waste.json';
var json_data3 = 'raw-data-run1-waste.json';
function add_chart(chart_id,json_data)
{
d3.json(json_data, function (data) {
nv.addGraph(function() {
var chart = nv.models.stackedAreaChart()
.margin(chartMargins)
.x(function(d) { return d[0] }) //We can modify the data accessor functions...
.y(function(d) { return d[1] }) //...in case your data is formatted differently.
.yDomain([0, yMax])
.useInteractiveGuideline(willHaveGuidelines) //Tooltips which show all data points. Very nice!
.rightAlignYAxis(true) //Let's move the y-axis to the right side.
.transitionDuration(500)
.showControls(willShowControls) //Allow user to choose 'Stacked', 'Stream', 'Expanded' mode.
.interactive(willBeInteractive)
.useVoronoi(willUseVoronoi)
.showLegend(false)
.forceX([946713600000, 4102473600000])
.color(["#1f77b4", "#aec7e8", "#ffbb78", "#2ca02c"])
.clipEdge(true);
//Format x-axis labels with custom function.
chart.xAxis
.tickValues([946713600000, 1738809360000, 2527749360000,
3316689360000, 4102473600000])
.tickFormat(function(d) {return d3.time.format('%Y')(new Date(d))})
.axisLabel('Year');
chart.yAxis
.axisLabel(yLabel)
.tickFormat(d3.format(',.f'));
d3.select(chart_id + ' svg')
.datum(data)
.attr(chartAttrs)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
});
}
if (kind == "cost")
{
yLabel = 'Cost in Millions of USD';
yMax = 30000;
var json_data1 = 'raw-data-run1-new-cost.json';
var json_data2 = 'raw-data-run3-new-cost.json';
var json_data3 = 'raw-data-run5-new-cost.json';
}
if (dynamic == true)
{
willHaveGuidelines = true;
}
add_chart('#chart1',json_data1);
add_chart('#chart2',json_data2);
add_chart('#chart3',json_data3);
}