gpt4 book ai didi

javascript - Highcharts 返回错误 14

转载 作者:搜寻专家 更新时间:2023-11-01 04:49:09 26 4
gpt4 key购买 nike

在花费数小时试图弄清楚如何将 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);

}

加载页面并检查错误控制台后,显示“Uncaught Highcharts error #14: www.highcharts.com/errors/14”。做错了什么,请帮帮我

最佳答案

Highcharts Error #14 清楚地说

String value sent to series.data, expected Number his happens if you pass in a string as a data point

数据点是 yValue,如果您的 serie.data 是以下形式

[y1,y2,y2] 

[[x1,y1],[x2,y2],[x3,y3]]

[
{ x : x1 ,y : y1 },
{ x : x2 ,y : y2 },
{ x : x3 ,y : y3 }
]

在上述任何形式中,y1y2y3 中存储的数据类型应该是数字。您只需在 javascript 中使用 parseFloat()parseInt() 即可实现此目的

var serie1 = usage_data.map( function(e) {
return [e.gateway, parseFloat(e.val)];
});

或者在您正在使用的服务器技术中进行
在 (PHP 4 >= 4.2.0, PHP 5) 中可以使用 floatval()

$float_value_of_var = floatval("123.456");

关于javascript - Highcharts 返回错误 14,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12485560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com