forked from arnicas/interactive-vis-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimple_barchart.html
76 lines (53 loc) · 1.61 KB
/
dimple_barchart.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
<!DOCTYPE html>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style>
body {
font-family: Arial;
padding: 50px;
}
.barsgroup {
margin-left: 20px;
}
.bars {
display: inline-block;
position: relative;
margin-right: 20px;
}
.title {
display: inline-block;
position: relative;
padding-left: 150px;
}
</style>
<body>
<h2>Bar Chart Using Dimple: Improved Water Supply 2015</h2>
<p>Percentage of regions (WHO) with access to clean water source, 2015.
<p>But let's talk about the categories graphed here... What's wrong with them?
<div class="bars"></div>
</div>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//dimplejs.org/dist/dimple.v2.1.6.min.js"></script>
<script>
function make_barvis(data, selector, color) {
// passing in the data array, an idenfitier to put the graph into, and a custom color
var svg = dimple.newSvg(selector, 600, 600);
var myChart = new dimple.chart(svg, data);
myChart.setBounds(190, 10, 400, 500); // x y width height
var xAxis = myChart.addMeasureAxis("x", "year2015");
xAxis.title = "Access to Clean Water (%)"; // custom label
var yAxis = myChart.addCategoryAxis("y", "name");
yAxis.title = "Region"; // custom label
yAxis.addOrderRule("year2015"); // largest at top!
myChart.defaultColors = [new dimple.color(color)];
myChart.addSeries(null, dimple.plot.bar);
myChart.draw();
}
function do_stuff(error, data) {
if (error) {
console.log("error reading file", error);
}
console.log(data);
make_barvis(data, ".bars", "red");
}
d3.csv("data/water_improvement_data.csv", do_stuff);
</script>