highcharts - 可变数据导致浏览器锁定

时间:2010-07-06 04:58:41

标签: javascript jquery highcharts

我正在尝试使用highcharts javascript库来使用此函数加载图表:

function create_chart(success, failed, pending)
{
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'graph',
            margin: [5, 5, 5, 5]
        },
        title: {
            text: 'Message Sending Status'
        },
        plotArea: {
            shadow: null,
            borderWidth: null,
            backgroundColor: null
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                dataLabels: {
                    enabled: true,
                    formatter: function() {
                        if (this.y > 5) return this.point.name;
                    },
                    color: 'white',
                    style: {
                        font: '13px Trebuchet MS, Verdana, sans-serif'
                    }
                }
            }
        },
        legend: {
            layout: 'vertical',
            style: {
                left: 'auto',
                bottom: 'auto',
                right: '50px',
                top: '100px'
            }
        },
        series: [{
                type: 'pie',
                name: 'Message Status',
                data: [
                    ['Successful Messages',   success],
                    ['Failed Messages',       failed],
                    ['Pending Messages',       pending]
                ]
            }]
    });
}

但这会锁定浏览器

我已将问题缩小到

data: [
   ['Successful Messages',   success],
   ['Failed Messages',       failed],
   ['Pending Messages',       pending]
]
好像我使用数字代替变量(即用12等替换成功) 然后它工作正常

这很令人困惑,因为使用console.log(成功)会返回12,那么可能导致这种情况呢?

1 个答案:

答案 0 :(得分:0)

data: [
   ['Successful Messages',   success - 0],
   ['Failed Messages',       failed - 0 ],
   ['Pending Messages',      pending - 0]
]

让我们看看这是否有用......