Skip to content

Instantly share code, notes, and snippets.

@chimerast
Last active August 29, 2015 14:11
Show Gist options
  • Save chimerast/6ae3a2ea039d83db6053 to your computer and use it in GitHub Desktop.
Save chimerast/6ae3a2ea039d83db6053 to your computer and use it in GitHub Desktop.
sample-gist

Japan Color

Color Mapping any data on Japan map. You can use any data about states of japan you have.

Data Format

States Data Label1 Data Label2 ...
State Data Data ...
都道府県 2011年 2012年 2013年
北海道 5467000 5442000 5412000
青森県 1360000 1347000 1333000
岩手県 1309000 1299000 1290000
宮城県 2315000 2315000 2317000
秋田県 1072000 1060000 1047000
山形県 1156000 1146000 1136000
福島県 1981000 1955000 1939000
茨城県 2919000 2907000 2894000
栃木県 1975000 1968000 1961000
群馬県 1966000 1959000 1950000
埼玉県 7117000 7126000 7134000
千葉県 6135000 6119000 6114000
東京都 12869000 12916000 12979000
神奈川県 8934000 8947000 8956000
新潟県 2351000 2336000 2319000
山梨県 1077000 1072000 1065000
長野県 1157000 1154000 1150000
富山県 793000 789000 784000
石川県 846000 841000 836000
福井県 2115000 2106000 2095000
岐阜県 2037000 2029000 2018000
静岡県 3694000 3683000 3668000
愛知県 7262000 7277000 7289000
三重県 1816000 1811000 1802000
滋賀県 1394000 1396000 1397000
京都府 2590000 2584000 2576000
大阪府 8699000 8697000 8690000
兵庫県 5505000 5496000 5483000
奈良県 1387000 1381000 1374000
和歌山県 990000 983000 975000
鳥取県 582000 578000 574000
島根県 708000 702000 697000
岡山県 1922000 1919000 1913000
広島県 2824000 2817000 2809000
山口県 1431000 1420000 1408000
徳島県 776000 772000 766000
香川県 985000 982000 979000
愛媛県 1416000 1408000 1398000
高知県 755000 749000 742000
福岡県 5038000 5044000 5047000
佐賀県 843000 840000 836000
長崎県 1411000 1402000 1391000
熊本県 1805000 1799000 1793000
大分県 1183000 1178000 1170000
宮崎県 1127000 1122000 1116000
鹿児島県 1693000 1684000 1674000
沖縄県 1393000 1401000 1407000
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
//# require=d3,topojson,jquery
var width = root.clientWidth;
var height = root.clientHeight;
var svg = d3.select(root).append('svg')
.attr('width', width)
.attr('height', height)
.attr('style', 'display: block; margin: auto;');
var projection = d3.geo.mercator()
.center([136, 35])
.scale(Math.min(width, height) * 2.0)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
svg.append('g')
.attr('id', 'legend_group');
d3.json('japan.topojson', function (error, json) {
svg.selectAll('.states')
.data(topojson.feature(json, json.objects.japan).features)
.enter().append('path')
.attr('stroke', 'gray')
.attr('stroke-width', '0.5')
.attr('id', function (d) { return 'state_' + d.properties.id})
.attr('class', 'states')
.attr('fill', '#ffffff')
.attr('d', path);
reload();
});
function update(data) {
var map = data.toMap({typed: true});
var key = map.header[2];
var values = map.values(key);
var color = d3.scale.linear()
.domain([d3.min(values), d3.max(values)])
.range(['#ffffff', '#ff0000'])
.interpolate(d3.interpolateLab);
if (svg.selectAll('.states').empty())
return false;
svg.selectAll('.states')
.attr('fill', function (d) {
if (map[d.properties.nam_ja] && $.isNumeric(map[d.properties.nam_ja][key])) {
return color(+map[d.properties.nam_ja][key]);
} else {
return '#ffffff';
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment