最近遇到了一個極其詭異的問題,剛剛解決,趕緊趁熱乎記錄下來。
問題是這樣的。最近在畫一張堆疊柱狀圖,橫坐標為周號(年+周),發現這個周沒有按照從大到小排列,為了排列,打算顯式給定echarts的橫坐標值。
這一指定就出事了:好好的chart 突然不顯示了。
配置項:
option = {
"tooltip": {
"trigger": "axis",
"axisPointer": {
"type": "shadow"
}
},
"legend": {
"type": "scroll",
},
"grid": {
"left": "3%",
"right": "4%",
"bottom": "3%",
"containLabel": true
},
"yAxis": {
"type": "value"
},
"xAxis": {
"type": "category",
"data": [ // 只要加上這個,圖就show 不出來;刪掉立馬能顯示
202242,
202241
]
},
"series": [
{
"name": "8",
"type": "bar",
"stack": "total",
"data": [
[
202241,
4
],
[
202242,
5
]
],
"itemStyle": {
"color": "rgb(94,154,215)"
}
},
{
"name": "11",
"type": "bar",
"stack": "total",
"data": [
[
202241,
3
],
[
202242,
8
]
],
"itemStyle": {
"color": "rgb(10,205,117)"
}
},
]
}
不加xAxis.data:
加上:
它也不報錯,但是chart就是不顯示出來,簡直詭異有木有!
最后各種招數都想了,突然福至靈心:xAxis是category,series 的data 的橫坐標值卻都是數字,會不會不匹配?
問題解決了╮(╯▽╰)╭