【问题标题】:highcharts - variable data causes browser lockuphighcharts - 可变数据导致浏览器锁定
【发布时间】:2010-07-06 04:58:40
【问题描述】:

我正在尝试使用 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(success) 返回 12,那么可能是什么原因造成的?

【问题讨论】:

    标签: javascript jquery highcharts


    【解决方案1】:

    试试

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

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

    【讨论】:

    • 嗯,完美运行,可能是什么原因造成的? (将尽快接受您的回答)
    • 我认为问题在于这些变量是字符串类型...所以将其转换为整数类型,我们减去0...当您调用create_chart(success, failed, pending)时,您是否在它的参数上加上引号?
    • 啊,我明白了,我认为 javascript 的类型很松散?
    • 是的,一个松散的类型......但这不是 JS 的错......也许插件中有一个类型检查,确保只接受数字而不是字符串......跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 2023-04-04
    • 2019-01-07
    • 2011-08-03
    • 2014-09-21
    • 2014-03-09
    • 1970-01-01
    相关资源
    最近更新 更多