简体   繁体   English

无法将动态数据获取到Jquery饼图中

[英]Unable to get dynamic data into Jquery pie chart

Not able to set dynamic data into my pie chart, please look into my code. 无法将动态数据设置到我的饼图中,请查看我的代码。 Hard coded code is working fine but dynamic data has an issue. 硬编码代码可以正常工作,但动态数据存在问题。

$(contact_listddd).each(function(index, data) {
                        total_kra=data.graph_count;
                        kra_type=data.kra_type;
                        abc+= '{name: "'+kra_type+'",y: '+total_kra+'},';
                     });

var result1 = abc.substring(0, abc.length-1);

                     $('#container2').highcharts({
                            chart: {
                                plotBackgroundColor: null,
                                plotBorderWidth: null,
                                plotShadow: false,
                                type: 'pie'
                            },
                            title: {
                                text: 'Browser market shares January, 2015 to May, 2015'
                            },
                            tooltip: {`enter code here`
                                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                            },
                            plotOptions: {
                                pie: {
                                    allowPointSelect: true,
                                    cursor: 'pointer',
                                    dataLabels: {
                                        enabled: false
                                    },
                                    showInLegend: true
                                }
                            },
                            series: [{
                                name: 'Brands',
                                colorByPoint: true,
                                data: [result1]
                            }]

                        });

If instead of result1 I hard code the data then it works fine. 如果我不是result1而是对数据进行硬编码,那么它将正常工作。 example below 下面的例子

series: [{
          name: 'Brands',
          colorByPoint: true,
          data: [{name: 'Firefox', y: 10.38 }, {name: 'Safari',y: 4.77}]
        }]

Data should contain an array of objects, so instead of storing string representation of objects, write like this: 数据应包含一个对象数组,因此与其存储对象的字符串表示形式,不如这样写:

var abc = [];

$(contact_listddd).each(function(index, data) {
                    total_kra=data.graph_count;
                    kra_type=data.kra_type;
                    abc.push({ name: kra_type, y: total_kra });
                 });

And then insert the array to the chart data 然后将数组插入图表数据

series: [{
  name: 'Brands',
  colorByPoint: true,
  data: abc
}]

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

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