[英]Plot a bar graph using Highcharts drilldown with two different JSON end points
[英]Is it possible to plot points on a line graph using two separate arrays? (highcharts)
我正在嘗試使用從 json 文件中提取的兩個單獨的 arrays 制作一個折線圖來創建折線圖。
這是我的 json 文件的樣子
{
"time": [1240, 1250, 1300, 1310],
"volt": [12.218, 13, 12, 14]
}
這是我認為可行的代碼https://codesandbox.io/s/boring-elbakyan-bj7gg?file=/data.json
它使用
data: {
x: jsonData.time,
y: jsonData.volt,
},
這對我來說似乎有意義但沒有用
這有效,但時間戳不顯示當前時間或根本不顯示https://codesandbox.io/s/awesome-hamilton-kkrgt?file=/index.js
任何幫助是極大的贊賞!!
您需要將 map 數據轉換為 Highcharts 所需的格式。在您的情況下:
具有[x, y]
值的 arrays 數組:
series: [{ data: jsonData2.time.map((x, index) => [x, jsonData2.volt[index]]) }]
或具有{ x, y }
值的對象數組:
series: [{ data: jsonData2.time.map((x, index) => ({ x: x, y: jsonData2.volt[index]})) }]
現場演示: https://codesandbox.io/s/fancy-cloud-mx9z-mx9ze?file=/index.js
API 參考: https://api.highcharts.com/highcharts/series.line.data
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.