{"id":4411,"date":"2015-08-03T19:49:05","date_gmt":"2015-08-03T10:49:05","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4411"},"modified":"2015-08-03T19:58:10","modified_gmt":"2015-08-03T10:58:10","slug":"post-4411","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4411","title":{"rendered":"\u30c1\u30e3\u30fc\u30c8\u306e\u51e1\u4f8b\u3092\u7c21\u5358\u306b\u4f5c\u6210\u3067\u304d\u308bD3\u30d7\u30e9\u30b0\u30a4\u30f3\u300cd3 Legend\u300d"},"content":{"rendered":"<p><a href=\"http:\/\/d3-legend.susielu.com\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend.jpg\" alt=\"d3_Legend\" width=\"562\" height=\"395\" class=\"aligncenter size-full wp-image-4417 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend.jpg 562w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend-213x150.jpg 213w\" sizes=\"auto, (max-width: 562px) 100vw, 562px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.cocohore11.com\/column\/14\/\">\u51e1\u4f8b\u3068\u306f\uff1f<\/a><\/p>\n<p>\u4e3b\u984c\u56f3\u3084\u30c1\u30e3\u30fc\u30c8\u306b\u306f\u6b20\u304b\u305b\u306a\u3044\u51e1\u4f8b\u3067\u3059\u304c\u3001D3.js\u3067\u306f\u3053\u306e\u5224\u4f8b\u3082\u81ea\u52d5\u7684\u306b\u751f\u6210\u306f\u3057\u3066\u304f\u308c\u306a\u3044\u306e\u3067\u81ea\u5206\u3067\u63cf\u753b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4ee5\u5916\u3068\u30e1\u30f3\u30c9\u30a6\u306a\u4f5c\u696d\u306a\u306e\u3067\u3059\u304c\u3001\u300c<a href=\"http:\/\/d3-legend.susielu.com\/\">d3 Legend<\/a>\u300d\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f7f\u3046\u3068d3.scale\u306e\u8a2d\u5b9a\u304b\u3089\u51e1\u4f8b\u3092\u7c21\u5358\u306b\u751f\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u975e\u5e38\u306b\u4fbf\u5229\u306a\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u306e\u3067\u662f\u975e\u3064\u304b\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u30b5\u30f3\u30d7\u30eb<\/h3>\n<p>\u30aa\u30fc\u30bd\u30c9\u30c3\u30af\u30b9\u306a\u7e26\u66f8\u304d\u306e\u51e1\u4f8b\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend1.jpg\" alt=\"d3_Legend1\" width=\"262\" height=\"146\" class=\"alignnone size-full wp-image-4412 border\" \/><\/p>\n<pre class=\"lang:js decode:true \" >var svg = d3.select('svg');\r\n\r\n\/\/\u30c1\u30e3\u30fc\u30c8\u3092\u63cf\u753b\u3059\u308b\u969b\u306b\u4f7f\u7528\u3059\u308b\u30b9\u30b1\u30fc\u30eb(\u6b63\u898f\u5316)\u95a2\u6570\r\nvar colorScale = d3.scale.linear()\r\n\t.domain([0, 100]).range([\"skyblue\", \"darkblue\"]);\r\n\r\n\/\/\u51e1\u4f8b\u3092\u914d\u7f6e\u3059\u308b\u30b0\u30eb\u30fc\u30d7\u8981\u7d20\u3092\u8ffd\u52a0\r\nvar legendView = svg.append(\"g\")\r\n  .attr(\"class\", \"legendQuant\")\r\n  .attr(\"transform\", \"translate(20,20)\");\r\n\r\n  \/\/\u30b9\u30b1\u30fc\u30eb\u3092\u5143\u306b\u51e1\u4f8b\u3092\u751f\u6210\u3059\u308b\r\nvar legend = d3.legend.color().scale(colorScale); \r\n\r\n\/\/\u51e1\u4f8b\u3092\u63cf\u753b\u3059\u308b\r\nlegendView.call(legend);<\/pre>\n<h3>\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/h3>\n<p>d3 Legend\u30d7\u30e9\u30b0\u30a4\u30f3\u306f\u3001\u8868\u793a\u3059\u308b\u51e1\u4f8b\u3092\u69d8\u3005\u306b\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u6a2a\u66f8\u304d\u306e\u51e1\u4f8b\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend2.jpg\" alt=\"d3_Legend2\" width=\"406\" height=\"103\" class=\"alignnone size-full wp-image-4413 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend2.jpg 406w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend2-300x76.jpg 300w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/p>\n<pre class=\"lang:js decode:true \" >var svg = d3.select('svg');\r\n\r\n\/\/\u30c1\u30e3\u30fc\u30c8\u3092\u63cf\u753b\u3059\u308b\u969b\u306b\u4f7f\u7528\u3059\u308b\u30b9\u30b1\u30fc\u30eb(\u6b63\u898f\u5316)\u95a2\u6570\r\nvar colorScale = d3.scale.linear()\r\n\t.domain([0, 100]).range([\"skyblue\", \"darkblue\"]);\r\n\r\n\/\/\u51e1\u4f8b\u3092\u914d\u7f6e\u3059\u308b\u30b0\u30eb\u30fc\u30d7\u8981\u7d20\u3092\u8ffd\u52a0\r\nvar legendView = svg.append(\"g\")\r\n  .attr(\"class\", \"legendQuant\")\r\n  .attr(\"transform\", \"translate(20,20)\");\r\n\r\n  \/\/\u30b9\u30b1\u30fc\u30eb\u3092\u5143\u306b\u51e1\u4f8b\u3092\u751f\u6210\u3059\u308b\r\nvar legend = d3.legend.color()\r\n\t.cells(11)\t\/\/\u8868\u793a\u3059\u308b\u30bb\u30eb\u306e\u6570\u3092\u6307\u5b9a\r\n\t.shapeWidth(30) \/\/\u5404\u30bb\u30eb\u306e\u6a2a\u5e45\u3092\u6307\u5b9a\u3059\u308b\r\n\t.orient('horizontal')\u3000\/\/\u6a2a\u5411\u304d\u306b\u3059\u308b\r\n\t.labelFormat(d3.format('d')) \/\/ \u30e9\u30d9\u30eb\u306e\u8868\u8a18\u3092\u6307\u5b9a\r\n\t.scale(colorScale); \r\n\r\n\/\/\u51e1\u4f8b\u3092\u63cf\u753b\u3059\u308b\r\nlegendView.call(legend);<\/pre>\n<h3>\u65e5\u672c\u5730\u56f3\u306b\u51e1\u4f8b\u3092\u4ed8\u3051\u3066\u307f\u308b<\/h3>\n<p>d3 Legend\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f7f\u3063\u3066\u5b9f\u969b\u306b\u90fd\u9053\u5e9c\u770c\u306e\u4eba\u53e3\u5225\u30b3\u30ed\u30d7\u30ec\u30b9\u56f3\u306b\u51e1\u4f8b\u3092\u4ed8\u3051\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/plug-in\/legend\/population\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend3.jpg\" alt=\"d3_Legend3\" width=\"506\" height=\"380\" class=\"alignnone size-full wp-image-4414 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend3.jpg 506w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend3-200x150.jpg 200w\" sizes=\"auto, (max-width: 506px) 100vw, 506px\" \/> <\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/plug-in\/legend\/population\/index.html\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >d3.json('http:\/\/shimz.me\/example\/d3js\/_geodata\/pref_population.geojson' , function(geojson){\r\n\t\r\n\t\/\/\u4eba\u53e3\u306e\u6700\u5927\u5024\u3092\u53d6\u5f97\t\r\n\tvar population_max = d3.max(geojson.features, function(d){\r\n\t\treturn +d.properties.population\r\n\t});\r\n\t\r\n\t\/\/\u30ab\u30e9\u30fc\u30b9\u30b1\u30fc\u30eb\u3092\u8a2d\u5b9a\t\r\n\tvar colorScale = d3.scale.linear().domain([0, population_max]).range(['skyblue', 'darkblue'])\r\n\t\r\n\t\/\/\u30d7\u30ed\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u8a2d\u5b9a\r\n\tvar projection = d3.geo.mercator()\r\n\t\t.scale(1000)\r\n\t\t.center([135, 36])\r\n\t\r\n\t\/\/\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\u751f\u6210\r\n\tvar path = d3.geo.path().projection(projection);\r\n\t\r\n\t\r\n\tvar svg = d3.select('svg');\r\n\t\r\n\t\/\/\u5730\u56f3\u3092\u8868\u793a\u3059\u308b\u30b0\u30eb\u30fc\u30d7\u8981\u7d20\r\n\tvar mapGroup = svg.append('g')\r\n\t\t\t.attr('transform', 'translate('+[-300, 0]+')');\r\n\t\r\n\t\/\/\u5730\u56f3\u63cf\u753b\r\n\tmapGroup.selectAll('path')\r\n\t\t.data(geojson.features)\r\n\t\t.enter()\r\n\t\t.append('path')\r\n\t\t.attr({\r\n\t\t\td:path,\r\n\t\t\tfill: function(d){ return colorScale(+d.properties.population) }\r\n\t\t})\r\n\t\r\n\t\/\/\u51e1\u4f8b\u3092\u8868\u793a\u3059\u308b\u30b0\u30eb\u30fc\u30d7\u8981\u7d20\r\n\tvar legendView = svg.append(\"g\")\r\n\t  .attr(\"class\", \"legendQuant\")\r\n\t  .attr(\"transform\", \"translate(20,20)\");\t\r\n\r\n\t\/\/\u30b9\u30b1\u30fc\u30eb\u3092\u5143\u306b\u51e1\u4f8b\u3092\u751f\u6210\u3059\u308b\r\n\tvar legend = d3.legend.color()\r\n\t\t.cells(5)\t\/\/\u8868\u793a\u3059\u308b\u30bb\u30eb\u306e\u6570\u3092\u6307\u5b9a\r\n\t\t.shapeWidth(30) \/\/\u5404\u30bb\u30eb\u306e\u6a2a\u5e45\u3092\u6307\u5b9a\u3059\u308b\r\n\t\t.scale(colorScale); \/\/\u51e1\u4f8b\u306e\u30b9\u30b1\u30fc\u30eb\u3092\u6307\u5b9a\r\n\t\r\n\t\/\/\u51e1\u4f8b\u3092\u63cf\u753b\u3059\u308b\r\n\tlegendView.call(legend);\t\r\n\t\r\n});\r\n<\/pre>\n<h3>\u30ab\u30c6\u30b4\u30ea\u306e\u51e1\u4f8b\u3092\u8868\u793a\u3059\u308b<\/h3>\n<p>\u5024\u4ee5\u5916\u306b\u30ab\u30c6\u30b4\u30ea\u3092\u8868\u3059\u51e1\u4f8b\u3068\u3044\u3046\u306e\u3082\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306f\u5404\u5186\u30b0\u30e9\u30d5\u306e\u8272\u304c\u4f55\u3092\u793a\u3057\u3066\u3044\u308b\u306e\u304b\u3092\u8aac\u660e\u3059\u308b\u51e1\u4f8b\u3092\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u63b2\u8f09\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/plug-in\/legend\/pie\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend4.jpg\" alt=\"d3_Legend4\" width=\"385\" height=\"242\" class=\"alignnone size-full wp-image-4416 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend4.jpg 385w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/08\/d3_Legend4-239x150.jpg 239w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/> <\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/plug-in\/legend\/pie\/index.html\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >\/\/\u5186\u30b0\u30e9\u30d5\u306e\u534a\u5f84\r\nvar r = 100;\r\n\/\/\u30ab\u30c6\u30b4\u30ea\r\nvar category = ['\u30ea\u30f3\u30b4', '\u30aa\u30ec\u30f3\u30b8', '\u30d0\u30ca\u30ca', '\u30a4\u30c1\u30b4', '\u30e2\u30e2'];\r\n\/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u30e9\u30f3\u30c0\u30e0\u306b\u8868\u793a\r\nvar dataSet = d3.range(5).map(function(d,i){ return {category:category[i], value:Math.floor(Math.random() * 10) + 1} });\r\n\r\n\/\/\u30ab\u30e9\u30fc\u30b9\u30b1\u30fc\u30eb\u3092\u30aa\u30ea\u30b8\u30ca\u30eb\u30b9\u30b1\u30fc\u30eb\u3068\u3057\u3066\u6307\u5b9a\u3059\u308b\r\nvar colorScale = d3.scale.ordinal()\r\n\t.domain(category)\t\/\/\u30ab\u30c6\u30b4\u30ea\u3092\u6307\u5b9a\r\n\t.range([ 'rgb(153, 107, 195)', 'rgb(56, 106, 197)', 'rgb(93, 199, 76)', 'rgb(223, 199, 31)', 'rgb(234, 118, 47)']);\r\n\r\nvar svg = d3.select('svg');\r\n\r\nvar arcsGroup = svg\r\n\t.data([dataSet])   \/\/pie\u3067\u5909\u63db\u3059\u308b\u305f\u3081\u306b\u8981\u7d20\uff11\u306e\u914d\u5217\u3068\u3057\u3066\u30c7\u30fc\u30bf\u3092\u6e21\u3059\r\n\t.append('g')\r\n\r\nvar pie = d3.layout.pie().value(function(d) { return d.value; });            \/\/\u5024\u304b\u3089startAngle,endAngle\u3092\u751f\u6210\u3059\u308b\r\nvar arc = d3.svg.arc().outerRadius(r).innerRadius(Math.floor(r\/2));      \/\/starAnge,endAngle\u304b\u3089d\u8981\u7d20\u3092\u751f\u6210\u3059\u308b\r\n\r\n var sliceGroup = arcsGroup.selectAll('g')     \r\n\t.data(pie)                       \r\n\t.enter()                        \r\n\t.append('g')                \r\n\t.attr('transform', 'translate('+ [250, 110] + ')' );   \r\n \r\n \/\/\u5186\u30b0\u30e9\u30d5\u63cf\u753b \r\n var slicePaths = sliceGroup.append('path')\r\n\t .attr({\r\n\t\t'd': arc,\r\n\t\t'fill': function(d, i){ return colorScale(category[i]) }\r\n\t}) \r\n\r\n\/\/\u51e1\u4f8b\u3092\u8868\u793a\u3059\u308b\u30b0\u30eb\u30fc\u30d7\u8981\u7d20\t\r\nsvg.append('g')\r\n\t.attr('class', 'legendLinear')\r\n\t.attr('transform', 'translate(20,20)');\r\n\r\n\/\/\u30b9\u30b1\u30fc\u30eb\u3092\u5143\u306b\u51e1\u4f8b\u3092\u751f\u6210\u3059\u308b\r\nvar legendLinear = d3.legend.color()\r\n\t.shapeWidth(30)\r\n\t.scale(colorScale);\r\n\r\n\/\/\u51e1\u4f8b\u3092\u63cf\u753b\u3059\u308b\r\nsvg.select('.legendLinear')\r\n  .call(legendLinear);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u51e1\u4f8b\u3068\u306f\uff1f \u4e3b\u984c\u56f3\u3084\u30c1\u30e3\u30fc\u30c8\u306b\u306f\u6b20\u304b\u305b\u306a\u3044\u51e1\u4f8b\u3067\u3059&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4417,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-4411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=4411"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4411\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4417"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}