What is the format of jQuery Flot data when passing in the data as variables

ε祈祈猫儿з 提交于 2019-12-09 07:32:28

I finally got it working when I realized that the data is supposed to be in jSON object notation. The old light bulb may be dim, but not entirely out. Here's the code:

function updatePieChart() {
    if ('#pieChart') {
        var total = 0;
        var data = new Array();
        var verb = "";
        var dataIndex = 0;
        var count = 0;

        for (var dataIndex = 0; dataIndex < 5; dataIndex++) {
            var duty = "DUTY_" + (dataIndex + 1);
            verb = getData(duty + "_SKILL");
            var d = getData(duty + "_PERCENTAGETIMESPENT");
            if (isNumeric(d)) {
                d = parseInt(d);
                if (d > 0) {
                    total += d;
                    if (verb == "") verb = duty + dataIndex;
                    var dataPoint = {
                        label: verb,
                        data: d
                    }
                    data[count++] = dataPoint;
                    log(dataPoint.label + ' = ' + dataPoint.data);
                }
            }
        }

        if (total != 100) {
            if (total < 100) {
                var missingDataNum = 100 - total;
                var dataPoint = {
                    label: '**MISSING**',
                    data: missingDataNum
                }
                data[count] = dataPoint;
                log(dataPoint.label + ' = ' + dataPoint.data);
            }
        }
        if ($.isFunction($.plot)) {
            log('Plot version: ' + $.plot.version);
            var pie = $.plot($('#pieChart'), data,
                {
                    series: {
                        pie: {
                            show: true,
                            label: {
                                show: true,
                                radius: 1,
                                formatter: function (label, series) {
                                    return '<div style="font-size:11px; text-align:center; padding:2px; color:black;">' + label + '<br />' + Math.round(series.percent) + '%</div>';
                                },
                                background: {
                                    opacity: 0.0
                                }
                            },
                            combine: {
                                color: '#999',
                                threshold: 0.05
                            }
                        }
                    },
                    legend: {
                        show: false,
                        labelFormatter: function (label, series) {
                            return '<b>' + label + '</b>';
                        }
                    }
                });
             }
        }
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!