Created
March 5, 2017 11:37
-
-
Save diggetybo/4c42aafc20c21e416585c9e37079eda2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v3.min.js"></script> | |
<style type="text/css"> | |
path:hover { | |
fill-opacity: .7; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var width = 960; | |
var height = 500; | |
var margins = { left: 0, top: 100, right: 210, bottom: 300 }; | |
var projection = d3.geo.mercator().center([105,38]) | |
.translate([width/2, height/2]) | |
.scale([600]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var color = d3.scale.linear() | |
.range(["#00fe80","#0005fd"]); | |
color.domain([23,1191]); | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", width+margins.right) | |
.attr("height", height+margins.top+margins.bottom); | |
var gradient = svg.append('defs') | |
.append('linearGradient') | |
.attr('id', 'gradient') | |
.attr('x1', '0%') | |
.attr('y1', '0%') | |
.attr('x2', '0%') | |
.attr('y2', '100%') | |
.attr('spreadMethod', 'pad'); | |
gradient.append('stop') | |
.attr('offset', '0%') | |
.attr('stop-color', '#0005fd') | |
.attr('stop-opacity', 1); | |
gradient.append('stop') | |
.attr('offset', '100%') | |
.attr('stop-color', '#00fe80') | |
.attr('stop-opacity', 1); | |
svg.append('rect') | |
.attr('width', 30) | |
.attr('height', (502)) | |
.attr('transform', 'translate(' + (margins.left+830) + ',' + (margins.top) + ')') | |
.style('fill','url(#gradient)'); | |
var scale = d3.scale.linear() | |
.domain([1191, 23]).nice() | |
.range([0, 500]); | |
var axis = d3.svg.axis().scale(scale).orient("right"); | |
var axisNodes = svg.append('g') | |
.attr('transform', 'translate(' + (margins.left+865) + ',' + (margins.top) + ')') | |
.call(axis); | |
styleAxisNodes(axisNodes); | |
svg.append('text') | |
.text('Oil Industry in China 2017') | |
.attr('font-size','48px') | |
.attr('transform', 'translate(' + 30 + ',' +90 + ')') | |
.attr('font-family','Play'); | |
d3.json("china_vehicles.json", function(error, json) { | |
svg.selectAll("path") | |
.data(json.features) | |
.enter() | |
.append("path") | |
.attr('class','topo_region') | |
.attr("d", path) | |
.attr('transform', 'translate(' + margins.left + ',' + margins.top + ')') | |
.style("stroke", "#fff") | |
.style("stroke-linejoin","round") | |
.style("stroke-width", "1.5") | |
.style("fill", function(d) { | |
return color(d.properties.vehicles) | |
}); | |
}); | |
function styleAxisNodes(axisNodes) { | |
axisNodes.selectAll('.domain') | |
.attr({ | |
fill: 'none', | |
'stroke-width': 2, | |
stroke: 'black' | |
}); | |
axisNodes.selectAll('.tick line') | |
.attr({ | |
fill: 'none', | |
'stroke-width': 2, | |
stroke: 'black' | |
}); | |
axisNodes.selectAll("text") | |
.attr({ | |
fill: 'black', | |
'font-family': 'play' | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment