在CHART JS上使用EVENTS

时间:2016-07-26 05:33:49

标签: javascript graph chart.js

我用 Chart JS

创建了这个简单的图形
<canvas id="myChart" width="200" height="200"></canvas>

<script>
    var ctx = document.getElementById("myChart").getContext("2d");

    var myDoughnutChart = new Chart(ctx, {
        type: 'doughnut',
        data: {
            labels: ["Banana", "Apple", "Orange"],
            datasets: [{
                data: [12, 15, 9],
                backgroundColor: [
                    'rgba(223, 105, 105, 0.6)',
                    'rgba(48, 104, 193, 0.6)',
                    'rgba(94, 234, 197, 0.6)'
                ],
                borderColor: [
                    'rgba(223, 105, 105, 0.6)',
                    'rgba(48, 104, 193, 0.6)',
                    'rgba(94, 234, 197, 0.6)'
                ],
                borderWidth: 1
            }]
        },
        options: {
            responsive: true,
            mode: 'label',
            maintainAspectRatio: true,
            animateRotate : true,
            title: {
                display: false,
                text: 'My Chart'
            },
            legend: {
                display: false
            },
            onClick: function() {
               alert("hallo");
            }
        }
    });
</script>

正如你所看到的,我有一个&#34; onCLick&#34;事件,但我不想要它,因为它适用于整个图表的点击。我正在寻找的是一种应用&#34;事件的方法&#34; &#34;的onclick&#34;对于我在图表上的每个不同数据。我已经阅读了Chart.js文档,发现&#34;事件&#34;函数需要一个Array [String],但由于我缺乏经验,我还没有成功对图表上的每个数据使用不同的操作。

任何建议都会有所帮助!

0 个答案:

没有答案