javascript Highcharts 返回错误 14
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12485560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts returning error 14
提问by MrFoh
Am trying to draw a pie chart with highcharts, after spending hours trying to figure out how process a JSON string into a javascript array. This is what i have
在花了几个小时试图弄清楚如何将 JSON 字符串处理成 javascript 数组之后,我正在尝试用 highcharts 绘制饼图。这就是我所拥有的
gateway_useage: function(usage_data) {
var options = {
chart: {
renderTo:'gateway-usage',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: { text: 'Gateway Usage' },
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Usage',
}]
}
var serie1 = usage_data.map( function(e) {
return [e.gateway, e.val];
});
options.series.push({data: serie1});
var chart = new Highcharts.Chart(options);
}
After loading the page and checking the error console saying "Uncaught Highcharts error #14: www.highcharts.com/errors/14 ". What am doing wrong, please help me out
加载页面并检查错误控制台后显示“Uncaught Highcharts error #14: www.highcharts.com/errors/14”。做错了什么,请帮帮我
回答by Jugal Thakkar
Highcharts Error #14clearly says
Highcharts 错误 #14清楚地说明
String value sent to series.data, expected Number his happens if you pass in a string as a data point
发送到 series.data 的字符串值,如果您将字符串作为数据点传入,则会发生预期的数字
data point is the yValue, if your serie.data
is of the form
数据点是 yValue,如果你serie.data
是这样的形式
[y1,y2,y2]
or
或者
[[x1,y1],[x2,y2],[x3,y3]]
or
或者
[
{ x : x1 ,y : y1 },
{ x : x2 ,y : y2 },
{ x : x3 ,y : y3 }
]
In any of the above forms the type of data stored in y1
,y2
& y3
should be numeric. You can achieve this my simply using the parseFloat()
or parseInt()
in javascript
在上述任何一种形式中y1
,存储在, y2
& 中的数据类型都y3
应该是数字。你可以简单地使用parseFloat()
或parseInt()
在javascript中实现这一点
var serie1 = usage_data.map( function(e) {
return [e.gateway, parseFloat(e.val)];
});
or do it in the server technology that you are using
In (PHP 4 >= 4.2.0, PHP 5) floatval()
can be used
或者在你使用的服务器技术中做
在(PHP 4 >= 4.2.0, PHP 5)floatval()
中可以使用
$float_value_of_var = floatval("123.456");