简体   繁体   English

Chartjs Graph未显示在colorbox中

[英]Chartjs Graph is not showing in colorbox

I am trying to display a Doughnut Chart in the popup(colorbox) with the dummy values but it is giving error, but if i simply call it in browser(via url) it display the graph. 我试图在弹出窗口(彩盒)中显示带有虚拟值的圆环图,但是它给出了错误,但如果我只是在浏览器中调用它(通过url)它会显示图形。

IndexSizeError: Index or size is negative or greater than the allowed amount. 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> 

Chart.js needs the canvas to have a rendered size before it can be rendered. Chart.js需要画布在渲染之前具有渲染大小。 So you need to have your chart initialization inside the cbox_complete event hook instead of doing it first and then opening the colorbox 因此,您需要在cbox_complete事件挂钩中进行图表初始化,而不是先执行此操作,然后再打开颜色框

Something like 就像是

$(document).bind('cbox_complete', function () {
    var DoughnutChart = [{
        ...

        ...
    var myDoughnutChart = new Chart(document.getElementById("canvas").getContext("2d")).Doughnut(DoughnutChart);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM