IndexSizeError:索引或大小为负数或大于允许的数量

时间:2017-03-09 07:10:13

标签: jquery json chart.js

我正在尝试向你的jQuery展示饼图。但它在使用chartJS显示图表时显示了我的错误。

这是我的JSON数据

{
  "serviceDataList" : [ {
    "value" : 9016514,
    "color" : "#fe3946",
    "highLight" : "#f30343",
    "label" : "Lab Order"
  }, {
    "value" : 5601661,
    "color" : "#a04c40",
    "highLight" : "#533e74",
    "label" : "Radiology Order"
  }, {
    "value" : 1779996,
    "color" : "#c0328d",
    "highLight" : "#35fe8d",
    "label" : "Service Order"
  }, {
    "value" : 156832,
    "color" : "#539568",
    "highLight" : "#0478ac",
    "label" : "Consultation"
  }, {
    "value" : 11720011,
    "color" : "#bbccbf",
    "highLight" : "#bb261c",
    "label" : "Medication Order"
  } ]
}

和我的HTML for chart:

<canvas id="myChart" width="256" height="256">

和我的脚本

var url="servicesListGraphDetails.json?fromDate="+form_date+"&toDate="+to_date+"&doctorId="+dotorid;
    $.getJSON(url, function(result){    
        console.log("result : "+result.serviceDataList);
        var ctx = $("#myChart").get(0).getContext("2d");
        var resultData = result.serviceDataList;
        var data = [];
        $.each(resultData, function (inx, val) {
            var obj = {};
            obj.color = val.color;
            obj.value = val.value;
            obj.label = val.label;
            obj.highLight=val.highLight;

            console.log(val.color);
            console.log(val.value);
            console.log(val.label);
            console.log(val.highLight);
            data.push(obj);
        });
        console.log("result: "+data);

        var piechart = new Chart(ctx).Pie(data);
    });

我得到了一个错误的错误

  

IndexSizeError:索引或大小为负数或大于允许值   amount ctx.arc(this.x,this.y,this.outerRadius,this.startAngle,   this.endAngle); Chart.js(第1225行)

0 个答案:

没有答案