Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

javascript - highcharts - variable data causes browser lockup

I am attempting to use the highcharts javascript library to load charts using this function:

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]
                ]
            }]
    });
}

however this locks the browser up

i have narrowed down the problem to

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

as if i use numbers in place of the variables (i.e replace success with 12 ect) then it works fine

this is confusing as using console.log(success) returns 12, so what could be causing this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try

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

lets see if this does a thing...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...