{"id":5250,"date":"2014-12-19T10:00:32","date_gmt":"2014-12-19T01:00:32","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=5250"},"modified":"2018-11-14T16:33:49","modified_gmt":"2018-11-14T07:33:49","slug":"d3-js%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e9%ad%85%e3%81%9b%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2014\/12\/19\/d3-js%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e9%ad%85%e3%81%9b%e3%82%8b\/","title":{"rendered":"D3.js\u3067\u30c7\u30fc\u30bf\u3092\u9b45\u305b\u308b!"},"content":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3001\u4f0a\u85e4\u3067\u3059\u3002 D3.js\u3068\u3044\u3046\u306e\u306f\u3001Web\u4e0a\u3067\u306e\u30c7\u30fc\u30bf\u53ef\u8996\u5316\u306e\u7528\u9014\u306b\u4f7f\u308f\u308c\u308b\u3053\u3068\u304c\u591a\u3044JavaScript\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3001\u30c7\u30fc\u30bf\u3092\u5143\u306bHTML\u3084CSS\u3092\u64cd\u4f5c\u3059\u308b\u4f7f\u3044\u52dd\u624b\u306e\u826f\u3044\uff08\u3068\u500b\u4eba\u7684\u306b\u306f\u601d\u3046\uff09\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u307e\u3041\u3001\u8a73\u3057\u3044\u3053\u3068\u306f\u516c\u5f0f\u30b5\u30a4\u30c8( http:\/\/d3js.org\/ )<\/a>\u3092\u898b\u3066\u3044\u305f\u3060\u304f\u3068\u3057\u3066\u3001\u3053\u306e\u6295\u7a3f\u3067\u306f\u3001\u305d\u3093\u306aD3.js\u306e\u3055\u308f\u308a\u3092\u30d0\u30d0\u3063\u3068\u7d39\u4ecb\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u305f\u3068\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306aJavaScript\u30c7\u30fc\u30bf\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059\u3002<\/p>\n \u3053\u306e\u30c7\u30fc\u30bf\u3092\u4f55\u3089\u304b\u306e\u5f62\u3067Web\u3067\u8868\u73fe\u3057\u305f\u3044\u3068\u3057\u307e\u3057\u3087\u3046\u3002\u4e00\u756a\u624b\u8efd\u305d\u3046\u306a\u306e\u306f\u3001li\u30bf\u30b0\u306e\u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u8868\u793a\u3059\u308b\u3053\u3068\u3067\u3059\u304b\u306d\u3002\u3056\u3063\u3068HTML\u3067\u66f8\u304f\u3068\u3053\u3093\u306a\u611f\u3058\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n \u3067\u3001\u3053\u306e\u3088\u3046\u306a\u30ea\u30b9\u30c8\u3092\u3001D3.js\u3067\u52d5\u7684\u306b\u751f\u6210\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n \u7d30\u304b\u304f\u30e1\u30bd\u30c3\u30c9\u306e\u8aac\u660e\u3092\u305b\u305a\u3068\u3082\u306a\u3093\u3068\u306a\u304f\u5185\u5bb9\u304c\u308f\u304b\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u6ce8\u76ee\u3059\u3079\u304d\u306fdata()\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u3088\u308a\u3001\u62bd\u51fa\u3057\u3066\u304d\u305fli\u8981\u7d20\u3068\u8868\u73fe\u3057\u305f\u3044testdata\u304c\u7d50\u3073\u3064\u304d\u307e\u3059\u3002\u3053\u306e\u6642\u70b9\u3067\u306fli\u8981\u7d20\u306f\u5b58\u5728\u3057\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u305d\u3053\u3067enter()\u3092\u547c\u3076\u3053\u3068\u3067testdata\u306b\u5bfe\u5fdc\u3059\u308b\u3082\u306e\u304c\u4eee\u7f6e\u304d\u3055\u308c\u3001\u305d\u3053\u3078\u3042\u3089\u305f\u3081\u3066li\u8981\u7d20\u3092\u52a0\u3048\u3066\u3044\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001testdata\u914d\u5217\u3068\u540c\u6570\u306eli\u8981\u7d20\u304c\u751f\u6210\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u3053\u306e\u3042\u305f\u308a\u306e\u8a73\u7d30\u306f\u3001\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306eSelections\u306e\u30da\u30fc\u30b8<\/a>\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff09<\/p>\n \u4e00\u822c\u7684\u306b\u306f\u3001testdata\u914d\u5217\u306e\u8981\u7d20\u306e\u6570\u3060\u3051\u30eb\u30fc\u30d7\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u3088\u308a\u610f\u8b58\u3055\u308c\u308b\u3088\u3046\u306a\u66f8\u304d\u65b9\uff08for<\/strong>\u3068\u304b .each(...)<\/strong> \u3068\u304b\uff09\u306b\u306a\u308b\u3053\u3068\u304c\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001D3.js\u306e\u5834\u5408\u306f\u3053\u306e\u3088\u3046\u306a\u3084\u3084\u5ba3\u8a00\u7684\u306a\u66f8\u304d\u65b9\u306b\u306a\u308a\u307e\u3059\u3002\u6700\u521d\u306f\u3061\u3087\u3063\u3068\u3068\u3063\u3064\u304d\u306b\u304f\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u6163\u308c\u308b\u3068\u306a\u304b\u306a\u304b\u7d20\u6575\u306a\u4ed5\u69d8\u306b\u601d\u3048\u3066\u304f\u308b\u306f\u305a\u3067\u3059\u3001\u305f\u3076\u3093\u3002<\/p>\n \u306a\u304a\u3001\u7d50\u3073\u3064\u3044\u305f\u5404\u30c7\u30fc\u30bf\u306b\u305d\u3063\u3066\u52d5\u7684\u306b\u5185\u5bb9\u3092\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u5185\u306etext()\u30e1\u30bd\u30c3\u30c9\u3067\u884c\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u95a2\u6570\u3092\u6e21\u3057\u307e\u3059\u3002\u3053\u306e\u95a2\u6570\u306e\u7b2c\u4e00\u5f15\u6570\u306f\u3001\u305d\u306e\u8981\u7d20\u306b\u7d50\u3073\u3064\u3044\u305f\u5404\u30c7\u30fc\u30bf\u3068\u306a\u308a\u3001\u7b2c\u4e8c\u5f15\u6570\u304c\u6e21\u3055\u308c\u305f\u9806\u756a\u3068\u306a\u308a\u307e\u3059\u3002\u5f15\u6570\u306f\u7701\u7565\u3057\u3066\u3082\u304b\u307e\u3044\u307e\u305b\u3093\u3002<\/p>\n \u3068\u3044\u3046\u308f\u3051\u3067\u3001\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u4f5c\u6210\u3055\u308c\u305f\u3082\u306e\u304c\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u30b5\u30f3\u30d7\u30eb\u30da\u30fc\u30b8\u3092\u76f4\u63a5\u8868\u793a<\/a>\uff09<\/p>\n
\n\u3053\u306e\u8a18\u4e8b\u306f\u3001TECHSCORE Advent Calendar<\/a> \u306e19\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b<\/h2>\n
\u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u8868\u793a<\/h3>\n
\r\nvar testdata = [\r\n {\"name\": \"A\", \"value\": 10},\r\n {\"name\": \"B\", \"value\": 20},\r\n {\"name\": \"C\", \"value\": 30},\r\n {\"name\": \"D\", \"value\": 50},\r\n {\"name\": \"E\", \"value\": 80},\r\n {\"name\": \"F\", \"value\":130},\r\n {\"name\": \"G\", \"value\":210}\r\n];<\/pre>\n
\r\n
\r\n
\r\nd3.select(\"body\").append(\"ul\")\r\n .selectAll(\"li\").data(testdata).enter()\r\n .append(\"li\").text(\r\n function(d) {\r\n return d[\"name\"] + \": \" + d[\"value\"];\r\n }\r\n );\r\n<\/pre>\n