highcharts.js:61 Error: attribute y: Expected length, "NaNNaN".錯誤的解決
使用highcharts.js繪圖時,在谷歌瀏覽器除錯時,控制檯顯示多條錯誤:如下圖所示
highcharts.js:61 Error: <text> attribute y: Expected length, "NaNNaN".
_defaultSetter @ highcharts.js:61
highcharts.js:61 Error: <text> attribute y: Expected length, "NaNNaNNaN".
_defaultSetter @ highcharts.js:61
highcharts.js:61 Error: <text> attribute y: Expected length, "NaNNaNNaNNaN".
_defaultSetter @ highcharts.js:61
highcharts.js:61 Error: <text> attribute y: Expected length, "NaNNaNNaNNaNNaN".
_defaultSetter @ highcharts.js:61
6highcharts.js:61 Error: <text> attribute y: Expected length, "NaNNaNNaNNaNNaNN…".
_defaultSetter @ highcharts.js:61
網上搜索一番,沒有人遇到跟我一樣的錯誤,只能自己想辦法解決,因為錯誤提示attribute y,所以我把重點放在Y軸的程式碼上,經過反覆除錯,終於找到問題所在,以下是我的繪圖程式碼(Y軸部分):
yAxis: {
title: {
text: "膽固醇(mmol/L)"
},
style: {
color: "#6D869F",
fontSize: "12px",
fontWeight: "normal"
},
plotBands: [{
from: 0,
to: 2.59,
zIndex: 0,
color: "#9AFF02",
style: {
opacity: 0.5
},
label: {
y: 20,
style:{
color: "#9AFF02"
}
},
from: 2.59,
to: 5.2,
zIndex: 0,
color: "#ECFFA8",
style: {
opacity: 0.5
},
label: {
y: 20,
style:{
color: "#C0FFC0"
}
}
},{
from: 5.2,
to: 10.35,
zIndex: 0,
color: "#C0FFC0",
style: {
opacity:0.5
},
label: {
text: "",
y: 20,
style:{
color: "#89691E"
}
}
}
],
}
原來是給圖形新增背景色的部分plotBands這裡設定了text屬性,但賦值為" ",這裡貼出那部分的程式碼:
from: 5.2,
to: 10.35,
zIndex: 0,
color: "#C0FFC0",
style: {
opacity:0.5
},
label: {
text: "",
y: 20,
style:{
color: "#89691E"
}
}
現在總算明白一些了,X軸、Y軸的title裡的text屬性賦值為" ",但plotBands這裡設定了text屬性,但賦值為" ",highcharts是不允許的。我的解決辦法是把plotBands的text屬性去掉,就不報這種錯誤了。