HighCharts-可变数据导致浏览器锁定
-
02-10-2019 - |
题
我正在尝试使用此功能使用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 ect替换成功),那么它可以正常工作
当使用console.log(成功)返回12时,这令人困惑,那么可能导致这一点呢?
解决方案
尝试
data: [
['Successful Messages', success - 0],
['Failed Messages', failed - 0 ],
['Pending Messages', pending - 0]
]
让我们看看这是否做了什么...
不隶属于 StackOverflow