{"id":2614,"date":"2013-03-11T19:09:07","date_gmt":"2013-03-11T10:09:07","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2614"},"modified":"2013-12-29T18:56:43","modified_gmt":"2013-12-29T09:56:43","slug":"post-2614","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2614","title":{"rendered":"\u3010D3.js\u3011 \u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3063\u305f\u30d2\u30fc\u30c8\u30de\u30c3\u30d7(Google Analytics \u53ef\u8996\u5316)"},"content":{"rendered":"<p>\u8272\u304c\u6fc3\u3044\u307b\u3069\u8a2a\u554f\u8005\u6570\u304c\u591a\u3044\u6642\u9593\u3068\u306a\u3063\u3066\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/shimz.me\/example\/d3js\/table\/01\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gsheatmap.jpg\" alt=\"gsheatmap\" width=\"737\" height=\"606\" class=\"alignleft size-full wp-image-2618\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gsheatmap.jpg 737w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gsheatmap-182x150.jpg 182w\" sizes=\"auto, (max-width: 737px) 100vw, 737px\" \/><\/a><\/p>\n<p>Google Analytics\u304b\u3089\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u305f\u30c7\u30fc\u30bf(\u65e5\u6642\u3001\u6642\u9593\u6bce\u306e\u8a2a\u554f\u8005\u6570)\u3092\u5143\u306bd3.js\u3092\u4f7f\u3063\u3066\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<br \/>\n\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30ab\u30b9\u30bf\u30e0\u30ec\u30dd\u30fc\u30c8\u3092\u4f5c\u6210\u3057CSV\u3067\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad31.jpg\" alt=\"gad31\" width=\"975\" height=\"261\" class=\"alignleft size-full wp-image-2615\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad31.jpg 975w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad31-300x80.jpg 300w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad31-768x206.jpg 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad32.jpg\" alt=\"gad32\" width=\"999\" height=\"352\" class=\"alignleft size-full wp-image-2616\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad32.jpg 999w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad32-300x106.jpg 300w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad32-768x271.jpg 768w\" sizes=\"auto, (max-width: 999px) 100vw, 999px\" \/><br \/>\n\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fcsv\u306b\u306f\u4f59\u8a08\u306a\u30ce\u30a4\u30ba\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u524a\u9664\u3057\u307e\u3059\u3002<br \/>\n\u2193\uff16\u884c\u76ee\u307e\u3067\u8981\u3089\u306a\u3044<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad33.jpg\" alt=\"gad33\" width=\"664\" height=\"396\" class=\"alignleft size-full wp-image-2617\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad33.jpg 664w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/gad33-252x150.jpg 252w\" sizes=\"auto, (max-width: 664px) 100vw, 664px\" \/><\/p>\n<p>\u3053\u308c\u3067\u30c7\u30fc\u30bf\u306e\u6e96\u5099\u304c\u5b8c\u6210\u3002<\/p>\n<hr>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/table\/01\/\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >d3.csv('ga.csv', function(csv){ \/\/csv\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\r\n\r\n\t\r\n\tvar max = d3.max(csv, function(d){ return d.visitors }); \/\/\u8a2a\u554f\u8005\u6570\u306e\u6700\u5927\u5024\u53d6\u5f97\r\n\t\r\n\tvar colorScale = d3.scale.linear().domain([0, max]).range([\"#FFF0F5\", \"#DC143C\"]); \/\/\u30ab\u30e9\u30fc\u30b9\u30b1\u30fc\u30eb\u3092\u4f5c\u6210\r\n\t\r\n\tvar  hours  = d3.range(24); \/\/\u6642\u9593\u8868\u793a\u7528\r\n\t\r\n\tvar data = \td3.nest().key(function(d){return d.date;}).entries(csv); \/\/CSV\u304b\u3089\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092date\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3067\u30cd\u30b9\u30c8\t\t\r\n\t\/\/console.log(data);\r\n\t\r\n\t\r\n\tvar tbody = d3.select('body').append('table').append('tbody'); \/\/table\u4f5c\u6210\r\n\tvar tfoot = d3.select('table').append('tfoot'); \/\/table\u306btfoot\u3092append\r\n\t\r\n\ttfoot.append('th'); \/\/\u7a7ath\u8ffd\u52a0\r\n\t\r\n\t\/\/tfoot\u306b\u6642\u9593th\u3092\u8ffd\u52a0\r\n\ttfoot.selectAll('class')\r\n\t\t.data(hours)\r\n\t\t.enter()\r\n\t\t.append('th')\r\n\t\t.attr(\"class\", \"hours\")\r\n\t\t.text(function(d){ return d});\r\n\t\r\n\t\r\n\t\/\/tr\u8ffd\u52a0\r\n\tvar trs = tbody.selectAll('tr')\r\n\t  .data(data)\r\n\t  .enter()\r\n\t  .append('tr')\r\n\t  \r\n\t \/\/th\u306b\u5e74\u6708\u65e5\u3092\u8ffd\u52a0\r\n\t trs.append('th').text(function(d){ \r\n\t\tvar Year = d.key.substring(0, 4);\r\n\t\tvar Month = d.key.substring(4, 6);\r\n\t\tvar Day = d.key.substring(6, 8);\r\n\t\tvar text = Year + \"\/\" + Month + \"\/\" + Day;\r\n\t\treturn text;\r\n\t});\r\n\r\n\t\r\n\t\/\/td\u8ffd\u52a0\r\n\ttrs.selectAll('td')\r\n\t   .data(function(d){ return d.values} )\r\n\t   .enter()\r\n\t   .append('td')\r\n\t   .style(\"background-color\", function(d){ return colorScale(d.visitors); })\r\n\t   .on('mouseover', function(d){\r\n\t\t\td3.select(this).text(d.visitors); \/\/mouover\u3057\u305f\u969b\u306b\u8a2a\u554f\u8005\u6570\u3092\u8868\u793a\r\n\t   })\r\n\t   .on(\"mouseout\", function(d){\r\n\t\t\td3.select(this).text(\"\");\t\t   \r\n\t   });\r\n\t  \r\n});<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8272\u304c\u6fc3\u3044\u307b\u3069\u8a2a\u554f\u8005\u6570\u304c\u591a\u3044\u6642\u9593\u3068\u306a\u3063\u3066\u307e\u3059\u3002 Go&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2618,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2614","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\/2614","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=2614"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2614\/revisions"}],"predecessor-version":[{"id":3249,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2614\/revisions\/3249"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2618"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}