简体   繁体   English

饼图使用flot

[英]Pie chart using flot

I am using Jquery Flot to create a pie chart based on three different values, pause, nopause and sleeping. 我正在使用Jquery Flot根据三个不同的值创建一个饼图,暂停,暂停和睡眠。 Initially it draws th pie chart correctly but after some redraw it gives me the following error. 最初它正确地绘制了饼图,但在重新绘制之后它给出了以下错误。

Could not draw pie with labels contained inside canvas 无法使用canvas中包含的标签绘制饼图

My code is 我的代码是

Lecturer.socket.onmessage = function (message) {

   var str = message.data;
   var msg = str.split(":");
   if(msg[0] == 'pause'){
       var pause = parseInt(msg[1]);
       var noPause = parseInt(msg[2]);
       var sleeping = parseInt(msg[3]);
       var data = [
          {label: "Pause", data:pause},
          {label: "No Pause", data:noPause},
          {label: "Sleeping", data:sleeping}
       ];
   var options = {
        series: {
            pie: {show: true}
        },
        legend: {
            show: false
        }
     };

    $.plot($("#pie-placeholder"), data, options);
}

}; };

HTML is HTML是

<div id="live-placeholder" class="flot"></div>

All the require js libraries are included. 包含所有需要的js库。 What I m doing wrong? 我做错了什么? Any Help ? 任何帮助?

Thanks 谢谢

You've got two problems: 你有两个问题:

1.) your placeholder div id doesn't match the $.plot call. 1.)你的占位符div id与$.plot调用不匹配。 live-placeholder != pie-placeholder . live-placeholder != pie-placeholder

2.) You don't need to calculate the percents yourself. 2.)您不需要自己计算百分比。 Flot will do it internally. Flot将在内部完成。

See a working fiddle here . 看到一个工作小提琴在这里

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

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