我试图在弹出窗口(彩盒)中显示带有虚拟值的圆环图,但是它给出了错误,但是如果我只是在浏览器中调用它(通过url)它会显示图形。
IndexSizeError:索引或大小为负数或大于允许的数量。
var DoughnutChart = [{
value: 60,
color: "#fcc79e"
}, {
value: 30,
color: "#beefd2"
}, {
value: 50,
color: "#ffddfb"
}, {
value: 20,
color: "#cdecff"
}, {
value: 90,
color: "#fff5bc"
}];
var myDoughnutChart = new Chart(document.getElementById("canvas").getContext("2d")).Doughnut(DoughnutChart);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<canvas id="canvas" height="450" width="600"></canvas>
答案 0 :(得分:2)
Chart.js需要画布在渲染之前具有渲染大小。因此,您需要在cbox_complete
事件挂钩内进行图表初始化,而不是首先执行此操作,然后打开颜色框
像
这样的东西$(document).bind('cbox_complete', function () {
var DoughnutChart = [{
...
...
var myDoughnutChart = new Chart(document.getElementById("canvas").getContext("2d")).Doughnut(DoughnutChart);
});