JSã°ã©ãã©ã¤ãã©ãªNVD3.jsã使ã£ã¦ã¯ã¦ãªããã°ã«ãã¤ã»ã³ã¹ãªæ ªä¾¡ãã£ã¼ãã表示ãããæ¹æ³
ä¹ ã ã«ããã°ã©ãã³ã°ç³»ã®ãã¿ã§ãã
ã¯ã¦ãªããã°ã«JavaScriptã®ã°ã©ãã©ã¤ãã©ãªã§ããNVD3.jsã使ç¨ãããã¤ã»ã³ã¹ãªæ ªä¾¡ãã£ã¼ãã表示ããã¦ã¿ã¾ãã
ãã¡ãããåæ§ã®æ¹æ³ã§æ£ã°ã©ããåã°ã©ããæãç·ã°ã©ãçã®åºæ¬ã°ã©ãããè¤åã°ã©ãçã®é«æ©è½ãªã°ã©ãã¾ã§ç°¡åã«è¡¨ç¤ºããããã¨ãã§ãã¾ãã
ï¼ï¼CSS/ã©ã¤ãã©ãªã®èªã¿è¾¼ã¿
ã¾ãã¯CSSã¨JavaScriptã©ã¤ãã©ãªãèªã¿è¾¼ã¿ã¾ãããã
ä¸è¨ã½ã¼ã¹ããã¼ã¸ä¸é¨ã«ã³ãã¼ãã¾ãã
<link href="http://cdn.rawgit.com/novus/nvd3/v1.8.4/build/nv.d3.css" rel="stylesheet" type="text/css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.2/d3.min.js" charset="utf-8"></script> <script src="http://cdn.rawgit.com/novus/nvd3/v1.8.4/build/nv.d3.js"></script>
ï¼ï¼ã°ã©ã表示ã¨ãªã¢
ã°ã©ãã表示ããããå ´æã«ä¸è¨ã³ã¼ããè¨è¼ãã¾ãã
<div id="chart1" style="height:400px;"> <svg></svg> </div>
ï¼ï¼JavaScriptæ¬ä½ã®è¨è¿°
æå¾ã«JavaScriptæ¬ä½ã®è¨è¿°ã§ãã
以ä¸ã®ãã©ã¼ãããã§ãã¼ã¿ã追å ãã¦ããã¾ãã
{"date": æ¥ä»ï¼1970å¹´1æ1æ¥ããã®çµéæ¥æ°ï¼, "open": å§å¤, "high": é«å¤, "low": å®å¤, "close": çµå¤},
ãã¼ã¿ã追è¨ãã¦ä»¥ä¸ã®ã½ã¼ã¹ãæå¾ã«è²¼ãä»ãã¾ãã
<script> var data = [{values: [ {"date": 16848, "open": 6150, "high": 6172, "low": 6011, "close": 6076}, {"date": 16849, "open": 6259, "high": 6293, "low": 6156, "close": 6180}, ããã«ãã¼ã¿ãè¨è¼ãã¦ãã ]}]; nv.addGraph(function() { var chart = nv.models.candlestickBarChart() .x(function(d) { return d['date'] }) .y(function(d) { return d['close'] }) .duration(250) .margin({left: 75, bottom: 100}); chart.xAxis .tickFormat(function(d) { return d3.time.format('%x')(new Date(d * 86400000)); }); chart.yAxis .tickFormat(function(d,i){ return '\ï¿¥' + d3.format(',.0f')(d); }); d3.select("#chart1 svg") .datum(data) .transition().duration(500) .call(chart); nv.utils.windowResize(chart.update); return chart; }); </script>
ï¼ï¼åä½ãµã³ãã«
ä¸è¨ã«ãã¨ã¿èªåè»ï¼7203ï¼ã®æ ªä¾¡ãã£ã¼ãã表示ãã¦ã¿ã¾ãã
Tooltipã表示ããã¦ãªããªããã¤ã»ã³ã¹ãªæ ªä¾¡ãã£ã¼ãã§ãï¼
- ä½è : ç©éç¥æ±
- åºç社/ã¡ã¼ã«ã¼: SBã¯ãªã¨ã¤ãã£ã
- çºå£²æ¥: 2015/10/30
- ã¡ãã£ã¢: åè¡æ¬
- ãã®ååãå«ãããã°ãè¦ã
ï¼ï¼ã»ãã«ããã¤ã»ã³ã¹ãªãµã³ãã«
ãã¼ãããã£ã¼ã
åã°ã©ãã®ã©ã¤ãã©ãªã¯ããè¦ããã¾ããããã¼ãããã£ã¼ãã¯é¢ç½ãã§ãã
<script> var testdata = [ {key: "10代", y: 5}, {key: "20代", y: 2}, {key: "30代", y: 9}, {key: "40代", y: 7}, {key: "50代", y: 4}, {key: "60代", y: 3}, {key: "70代", y: 0.5} ]; var height = 350; var width = 350; var chart1; nv.addGraph(function() { var chart1 = nv.models.pieChart() .x(function(d) { return d.key }) .y(function(d) { return d.y }) .donut(true) .width(width) .height(height) .padAngle(.08) .cornerRadius(5) .id('donut1'); chart1.title("100%"); chart1.pie.donutLabelsOutside(true).donut(true); d3.select("#test1") .datum(testdata) .transition().duration(1200) .call(chart1); return chart1; }); </script>
æ£å¸å³
ã©ã³ãã ã§æ£å¸å³ãæç»ãããµã³ãã«ã§ãã
æ£å¸å³ã¯å½¢ç¶ãè²ã§ã°ã«ã¼ãã³ã°ã§ãã¦ãªããªããã¤ã»ã³ã¹ã§ããï¼
<script> nv.utils.symbolMap.set('thin-x', function(size) { size = Math.sqrt(size); return 'M' + (-size/2) + ',' + (-size/2) + 'l' + size + ',' + size + 'm0,' + -(size) + 'l' + (-size) + ',' + size; }); var chart; nv.addGraph(function() { chart = nv.models.scatterChart() .showDistX(true) .showDistY(true) .useVoronoi(true) .color(d3.scale.category10().range()) .duration(300) ; chart.dispatch.on('renderEnd', function(){ console.log('render complete'); }); chart.xAxis.tickFormat(d3.format('.02f')); chart.yAxis.tickFormat(d3.format('.02f')); d3.select('#test2 svg') .datum(randomData(4,40)) .call(chart); nv.utils.windowResize(chart.update); chart.dispatch.on('stateChange', function(e) { ('New State:', JSON.stringify(e)); }); return chart; }); function randomData(groups, points) { var data = [], shapes = ['thin-x', 'circle', 'cross', 'triangle-up', 'triangle-down', 'diamond', 'square'], random = d3.random.normal(); for (i = 0; i < groups; i++) { data.push({ key: 'Group ' + i, values: [] }); for (j = 0; j < points; j++) { data[i].values.push({ x: random(), y: random(), size: Math.round(Math.random() * 100) / 100, shape: shapes[j % shapes.length] }); } } return data; } </script>
é¢é£ã°ã©ã
ãã¸ã¥ã¢ã«çã«ä¸çºã§é¢é£æ§ããããã°ã©ããæç»ã§ãã¾ãã
SNSãªããã§ä½¿ãããã
<script> nv.addGraph({ generate: function() { var d3Colors = d3.scale.category20(); var chart = nv.models.forceDirectedGraph() .width(500) .height(700) .color(function(d) { return d3Colors(d.group) }) .nodeExtras(function(node) { node .append("text") .attr("dx", 12) .attr("dy", ".35em") .text(function(d) { return d.name }); }); d3.select('#test3') .datum(all_data) .call(chart); return chart; } }); </script> <script> var all_data = { "nodes":[ {"name":"å±±ç°","group":1}, {"name":"é´æ¨","group":1}, {"name":"é«æ©","group":2}, {"name":"æ¾ç°","group":3}, {"name":"å·ä¸","group":1}, {"name":"å·ä¸","group":2}, {"name":"ç¦å²¡","group":1}, {"name":"å¥åº","group":3}, {"name":"å","group":1}, {"name":"å³°","group":1}, {"name":"ä¸å³¶","group":2}, {"name":"岡å´","group":2}, {"name":"æ¬ç°","group":3} ], "links":[ {"source":1,"target":0,"value":1}, {"source":2,"target":0,"value":1}, {"source":3,"target":0,"value":1}, {"source":4,"target":0,"value":1}, {"source":5,"target":0,"value":1}, {"source":6,"target":0,"value":1}, {"source":7,"target":0,"value":1}, {"source":8,"target":0,"value":1}, {"source":9,"target":0,"value":1}, {"source":10,"target":0,"value":1}, {"source":11,"target":0,"value":1}, {"source":12,"target":0,"value":1}, {"source":7,"target":3,"value":1}, {"source":8,"target":5,"value":1}, {"source":9,"target":6,"value":1}, {"source":10,"target":1,"value":1}, {"source":11,"target":7,"value":1}, {"source":12,"target":6,"value":1} ] } </script>