コスパ重視で生きたい人生だった

なるべく楽して生きて行きたい30代サラリーマンのブログ

Javascriptでグラフを書いてみる その2


f:id:dett0826:20151011011943j:plain
前回の続き。
Chart.jsでグラフを書いてみる。
のこり3サンプルの紹介。

www.cospa14.com


前回紹介できなかったのこり3種紹介。
鶏頭図は日本じゃあんまりなじみの無いグラフかも。

レーダーチャート


サンプルコード

<canvas id="radar" height="300" width="300"></canvas>
<script>
var data = {
    labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 90, 81, 56, 55, 40]
        },
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.2)",
            strokeColor: "rgba(151,187,205,1)",
            pointColor: "rgba(151,187,205,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 96, 27, 100]
        }
    ]
};
var myRadarChart = new Chart(document.getElementById("radar").
getContext("2d")).Radar(data);
</script>
円グラフ

サンプルコード

<canvas id="Pie" height="300" width="300"></canvas>
<script>
var data = [
    {
        value: 300,
        color:"#F7464A",
        highlight: "#FF5A5E",
        label: "Red"
    },
    {
        value: 50,
        color: "#46BFBD",
        highlight: "#5AD3D1",
        label: "Green"
    },
    {
        value: 100,
        color: "#FDB45C",
        highlight: "#FFC870",
        label: "Yellow"
    }
]
var myPieChart = new Chart(document.getElementById("Pie").getContext("2d")).Pie(data);
</script>||<

***鶏頭図
<canvas id="PolarArea" height="300" width="300"></canvas>
<script>
var data = [
    {
        value: 300,
        color:"#F7464A",
        highlight: "#FF5A5E",
        label: "Red"
    },
    {
        value: 50,
        color: "#46BFBD",
        highlight: "#5AD3D1",
        label: "Green"
    },
    {
        value: 100,
        color: "#FDB45C",
        highlight: "#FFC870",
        label: "Yellow"
    },
    {
        value: 40,
        color: "#949FB1",
        highlight: "#A8B3C5",
        label: "Grey"
    },
    {
        value: 120,
        color: "#4D5360",
        highlight: "#616774",
        label: "Dark Grey"
    }

];
new Chart(document.getElementById("PolarArea").getContext("2d")).PolarArea(data);
</script>
サンプルコード
>|javascript|

<canvas id="PolarArea" height="300" width="300"></canvas>
<script>
var data = [
    {
        value: 300,
        color:"#F7464A",
        highlight: "#FF5A5E",
        label: "Red"
    },
    {
        value: 50,
        color: "#46BFBD",
        highlight: "#5AD3D1",
        label: "Green"
    },
    {
        value: 100,
        color: "#FDB45C",
        highlight: "#FFC870",
        label: "Yellow"
    },
    {
        value: 40,
        color: "#949FB1",
        highlight: "#A8B3C5",
        label: "Grey"
    },
    {
        value: 120,
        color: "#4D5360",
        highlight: "#616774",
        label: "Dark Grey"
    }

];
new Chart(document.getElementById("PolarArea").getContext("2d")).PolarArea(data);
</script>