MrF*_*Foh 4 javascript highcharts
我花了好几个小时试图找出如何将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);
}
Run Code Online (Sandbox Code Playgroud)
加载页面并检查错误控制台"Uncaught Highcharts error#14:www.highcharts.com/errors/14"后.出了什么问题,请帮帮我
Jug*_*kar 15
发送到series.data的字符串值,如果您将字符串作为数据点传入,则会发生数字
数据点是yValue,如果你serie.data的形式是
[y1,y2,y2]
Run Code Online (Sandbox Code Playgroud)
要么
[[x1,y1],[x2,y2],[x3,y3]]
Run Code Online (Sandbox Code Playgroud)
要么
[
{ x : x1 ,y : y1 },
{ x : x2 ,y : y2 },
{ x : x3 ,y : y3 }
]
Run Code Online (Sandbox Code Playgroud)
在任一数据的类型存储在上述形式y1,y2及y3应为数值.您只需使用parseFloat()或parseInt()在javascript中即可实现此目的
var serie1 = usage_data.map( function(e) {
return [e.gateway, parseFloat(e.val)];
});
Run Code Online (Sandbox Code Playgroud)
或做它在所使用的服务器技术
在(PHP 4> = 4.2.0,PHP 5) floatval(),可以使用
$float_value_of_var = floatval("123.456");
Run Code Online (Sandbox Code Playgroud)