-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate-choropleth 2.html
More file actions
75 lines (66 loc) · 1.97 KB
/
state-choropleth 2.html
File metadata and controls
75 lines (66 loc) · 1.97 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Plotly JS Example</title>
<script src="https://d3js.org/d3.v7.min.js"></script>
<!-- Load plotly.js into the DOM -->
<script src='https://cdn.plot.ly/plotly-2.26.0.min.js'></script>
<style>
#myDiv{
width:600px;
height:400px;
border:1px solid silver;
}
</style>
</head>
<body>
<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>
<script>
let parser = (d) => d;
d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv', parser)
.then(rows => {
function unpack(rows, key) {
return rows.map(function (row) { return row[key]; });
}
var data = [{
type: 'choropleth',
locationmode: 'USA-states',
locations: unpack(rows, 'code'),
z: unpack(rows, 'total exports'),
text: unpack(rows, 'state'),
zmin: 0,
zmax: 17000,
colorscale: [
[0, 'rgb(242,240,247)'], [0.2, 'rgb(218,218,235)'],
[0.4, 'rgb(188,189,220)'], [0.6, 'rgb(158,154,200)'],
[0.8, 'rgb(117,107,177)'], [1, 'rgb(84,39,143)']
],
colorbar: {
title: 'Millions USD',
thickness: 0.2
},
marker: {
line:{
color: 'rgb(255,255,255)',
width: 2
}
}
}];
var layout = {
// title: '2011 US Agriculture Exports by State',
geo:{
scope: 'usa',
showlakes: true,
lakecolor: 'rgb(255,255,255)'
},
margin:{l:0,r:0,t:0,b:0,pad:0},
showlegend:false
};
Plotly.newPlot("myDiv", data, layout, {showLink: false});
});
</script>
</body>
</html>