|
9 | 9 | ---
|
10 | 10 |
|
11 | 11 | Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv', function(err, rows){
|
12 |
| - function unpack(rows, key) { |
13 |
| - return rows.map(function(row) { return row[key]; }); |
14 |
| - } |
| 12 | + function unpack(rows, key) { |
| 13 | +return rows.map(function(row) { return row[key]; }); |
| 14 | +} |
| 15 | +var data = [{ |
| 16 | + type: 'choropleth', |
| 17 | + locationmode: 'USA-states', |
| 18 | + locations: unpack(rows, 'Postal'), |
| 19 | + z: unpack(rows, 'Population'), |
| 20 | + text: unpack(rows, 'State'), |
| 21 | + autocolorscale: true |
| 22 | +}]; |
15 | 23 |
|
16 |
| - var data = [{ |
17 |
| - type: 'choropleth', |
18 |
| - locationmode: 'USA-states', |
19 |
| - locations: unpack(rows, 'postal'), |
20 |
| - z: unpack(rows, 'pop'), |
21 |
| - text: unpack(rows, 'state'), |
22 |
| - autocolorscale: true |
23 |
| - }]; |
24 |
| - |
25 |
| - |
26 |
| - var layout = { |
27 |
| - title: '2014 US Population by State', |
28 |
| - geo:{ |
29 |
| - scope: 'usa', |
30 |
| - countrycolor: 'rgb(255, 255, 255)', |
31 |
| - showland: true, |
32 |
| - landcolor: 'rgb(217, 217, 217)', |
33 |
| - showlakes: true, |
34 |
| - lakecolor: 'rgb(255, 255, 255)', |
35 |
| - subunitcolor: 'rgb(255, 255, 255)', |
36 |
| - lonaxis: {}, |
37 |
| - lataxis: {} |
38 |
| - } |
39 |
| - }; |
40 |
| - Plotly.plot(myDiv, data, layout, {showLink: false}); |
41 |
| -}); |
| 24 | +var layout = { |
| 25 | +title: '2014 US Popultaion by State', |
| 26 | + geo:{ |
| 27 | + scope: 'usa', |
| 28 | + countrycolor: 'rgb(255, 255, 255)', |
| 29 | + showland: true, |
| 30 | + landcolor: 'rgb(217, 217, 217)', |
| 31 | + showlakes: true, |
| 32 | + lakecolor: 'rgb(255, 255, 255)', |
| 33 | + subunitcolor: 'rgb(255, 255, 255)', |
| 34 | + lonaxis: {}, |
| 35 | + lataxis: {} |
| 36 | + } |
| 37 | +}; |
| 38 | +Plotly.plot(myDiv, data, layout, {showLink: false}); |
| 39 | +}); |
0 commit comments