{"id":3743,"date":"2014-09-15T10:14:27","date_gmt":"2014-09-15T01:14:27","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3743"},"modified":"2018-09-18T16:49:28","modified_gmt":"2018-09-18T07:49:28","slug":"post-3743","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3743","title":{"rendered":"\u3010D3.js\u3011Google Map\u4e0a\u306b\u68d2\u30b0\u30e9\u30d5\u3092\u8868\u793a\u3059\u308b"},"content":{"rendered":"<p><a href=\"https:\/\/shimz.me\/datavis\/gunma\/maebashi\/population\/bar.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/09\/barmap140915.jpg\" alt=\"Google Map\u4e0a\u306b\u68d2\u30b0\u30e9\u30d5\u3092\u8868\u793a\u3059\u308b\" width=\"590\" height=\"453\" class=\"aligncenter size-full wp-image-3744\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/09\/barmap140915.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/09\/barmap140915-195x150.jpg 195w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/shimz.me\/datavis\/gunma\/maebashi\/population\/bar.html\">example<\/a><\/p>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3733\">\u5186\u30b0\u30e9\u30d5<\/a>\u306b\u5f15\u304d\u7d9a\u304d\u3001\u68d2\u30b0\u30e9\u30d5\u3092\u5730\u56f3\u4e0a\u306b\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u68d2\u30b0\u30e9\u30d5\u306f\u9ad8\u3055\u306e\u30b9\u30b1\u30fc\u30eb\u3092\u8a2d\u5b9a\u3059\u308b\u306e\u304c\u96e3\u3057\u3044\u3067\u3059\u306d\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u4eca\u56de\u3082\u3001Google Maps API\u306edraw\u30e1\u30bd\u30c3\u30c9\u5185\u3060\u3051\u53c2\u8003\u306b\u8f09\u305b\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >overlay.draw = function () {\n    var index = getIndex(); \u3000\/\/\u9078\u629e\u3055\u308c\u3066\u3044\u308b\u9805\u76ee\u3092\u53d6\u5f97\n    \n    \/\/\u30d4\u30af\u30bb\u30eb\u30dd\u30b8\u30b7\u30e7\u30f3\u60c5\u5831\n    pointdata.forEach(function(d) {\n        var point = googleMapProjection([d['X_CODE'] ,d['Y_CODE']]);\/\/\u4f4d\u7f6e\u60c5\u5831\u2192\u30d4\u30af\u30bb\u30eb\n        d['xpoint'] = point[0];\n        d['ypoint'] = point[1];\n    });\n    \n    \/\/\u6700\u5927\u5024\u53d6\u5f97\n    var max = d3.max(pointdata, function(d){\n        if (+d['\u5973\u306e\u7dcf\u6570'] > +d['\u7537\u306e\u7dcf\u6570']) {\n            return +d['\u5973\u306e\u7dcf\u6570']\n        }else{\n            return +d['\u7537\u306e\u7dcf\u6570']                   \n        }\n    });\n    \n    \/\/\u68d2\u30b0\u30e9\u30d5\u306e\u9ad8\u3055\u30b9\u30b1\u30fc\u30eb\u3092\u8a2d\u5b9a\n    var barH = 100;\n    var barW = 8;\n    var yScale = d3.scale.linear().domain([0, max]).range([0, barH]);\n    \n    \/\/\u524d\u306e\u30b0\u30e9\u30d5\u3092\u3059\u3079\u3066\u524a\u9664\u3059\u308b\n    d3.selectAll(\".bar\").remove()\n    \n    \/\/\u30c7\u30fc\u30bf\u306e\u6570\u3060\u3051\u68d2\u30b0\u30e9\u30d5\u3092\u66f8\u304f\n    pointdata.forEach(function(point){\n        if (+point['\u7537'+index] <= 0 &#038;&#038; +point['\u5973'+index] <= 0) return ;  \/\/\u7537\u5973\u3068\u3082\u306b\uff10\u4eba\u306e\u5834\u5408\u306f\u629c\u3051\u308b\n        \n        \/\/\u68d2\u30b0\u30e9\u30d5\u4f5c\u6210\u7528\u306e\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f5c\u308b\n        var data = [\n            {key:\"\u7537\", value:point['\u7537'+index], city:point.CITYNAME, town:point.NAME},\n            {key:\"\u5973\", value:point['\u5973'+index], city:point.CITYNAME, town:point.NAME}\n        ];\n            \n        \/\/\u68d2\u30b0\u30e9\u30d5\u30b0\u30eb\u30fc\u30d7\n        var barGroup = gunmalayer \/\/Gmap\u4e0a\u306esvg\u30ec\u30a4\u30e4\n            .append(\"g\")\n            .attr(\"class\", \"bar\")\n            .attr(\"transform\", \"translate(\" + point.xpoint+ \",\" + point.ypoint + \")\")\u3000\/\/\u5186\u30b0\u30e9\u30d5\u3092\u8868\u793a\u3059\u308b\u5ea7\u6a19\u3092\u6307\u5b9a\n        \n        \/\/\u68d2\u30b0\u30e9\u30d5\u63cf\u753b\n        var bar = barGroup.selectAll(\"rect\")\n            .data(data)\n            .enter()\n            .append(\"rect\")\n            .attr({\n                x:function(d,i){ return i * barW - (barW\/2) },\n                y:function(d){ return barH - yScale(d.value) },\n                width:barW,\n                height:function(d){ return yScale(d.value) },\n                stroke:\"black\",\n                fill:function(d, i){\n                    if (i == 0) {\n                        return \"blue\";\n                    }else{\n                        return \"red\";\n                    }\n                    \n                }\n            });\n        \n        \/\/\u30de\u30a6\u30b9\u30aa\u30fc\u30d0\u30fc\u3057\u305f\u969b\u306b\u8a73\u7d30\u3092\u8868\u793a      \n        bar.append(\"title\")\n            .text(function(d){ return d.town + \" \" + d.key + \"\uff1a\" +d.value + \"\u4eba\" })\n                        \n    });\n};<\/pre>\n<p>D3.js\u3092\u4f7f\u3066Google Map\u4e0a\u306bSVG\u3092\u8868\u793a\u3059\u308b\u65b9\u6cd5\u306f\u4ee5\u4e0b\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n<span class=\"removed_link\" title=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2379\">\u3010D3.js\u3011Google Map\u306bSVG\u3092\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3059\u308b(SHAPE\u30c7\u30fc\u30bf\u8efd\u91cf\u5316)<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>example \u5186\u30b0\u30e9\u30d5\u306b\u5f15\u304d\u7d9a\u304d\u3001\u68d2\u30b0\u30e9\u30d5\u3092\u5730\u56f3&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3744,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,37],"tags":[],"class_list":["post-3743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","category-google-map-api","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3743","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=3743"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3743\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/3744"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}