Chart.js ã§å¡ä¾ã表示ãã
Chart.js ã®åã°ã©ãã§å¡ä¾ã表示ãã¦ã¿ã¾ããã
ã¡ãªã¿ã«è©¦ããã®ã¯ Chart.js ã® Version 1.0.1 beta-2 ã§ãã
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Chart.jsã§å¡ä¾ä»ãåã°ã©ã</title> <script src="Chart.min.js"></script> <style> .center { margin-left: auto; margin-right: auto; text-align: center; } #pieLegend { padding: 10px; overflow: hidden; position: relative; } ul.pie-legend { list-style: none outside none; float: left; margin: 0 0 0 0; padding: 0; position: relative; left: 50%; } ul.pie-legend > li { float: left; margin-right: 5px; padding: 5px; position: relative; left: -50%; } </style> </head> <body> <div id="chartArea" class="center"> <canvas id="pieArea" height="200" width="200"></canvas> <div id="pieLegend"></div> </div> <script> // åã°ã©ãç¨ãã¼ã¿ // ãã®å¤æ°åã legendTemplate ã®ä¸ã§ä½¿ã£ã¦ããã®ã§æ³¨æ var datasets = [ { value: 70, color: "green", lineColor: "green", // å¡ä¾ã®è² highlight: "seagreen", label: "ç·" // å¡ä¾ã®ã©ãã« }, { value: 30, color: "gold", lineColor: "gold", // å¡ä¾ã®è² highlight: "yellow", label: "é»è²" // å¡ä¾ã®ã©ãã« } ]; // ãªãã·ã§ã³ var options = { // å¡ä¾è¡¨ç¤ºç¨ã® HTML ãã³ãã¬ã¼ã legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].lineColor%>\"> </span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>" }; // åã°ã©ãæç» var myPie = new Chart(document.getElementById("pieArea").getContext("2d")).Pie(datasets, options); // generateLegend() ã®åºåã HTML ã«å ¥ãã document.getElementById("pieLegend").innerHTML = myPie.generateLegend(); </script> </body> </html>
ããã§ä»¥ä¸ã®ãããªæãã§å¡ä¾ã表示ããã¾ãã
åãã£ã¦ãã¾ãã°ãªãã¦äºã¯ãªãã£ããã§ãããæåã¡ãã£ã¨åããã¥ããã£ãã§ãã
ChartNew.js ã ã¨ãªãã·ã§ã³ã« legend: true ãæå®ããã ãã ã£ããããã®ã§ããã å¡ä¾ã表示ãããã ããªã ChartNew.js ã®æ¹ãç°¡åã§ããã
åè
HTML5 à Chart.jsã§åã°ã©ããæã | ãã¸ã¥ã¢ã«ã·ã³ãã³ã°
http://www.visualthinking.jp/archives/13390
HTML5 à Chart.jsã§åã°ã©ããæãï¼ãªãã·ã§ã³æå®æ¹æ³ï¼ | ãã¸ã¥ã¢ã«ã·ã³ãã³ã°
http://www.visualthinking.jp/archives/13463