echarts中xAxis的type=‘time’

當type=time時,x軸不需要再另外設置data。
只需要再series中的data設爲二維數組,每個元素是時間戳和值。
此時x軸會自定刻度間隔,需要自定義的話,使用splitNumber屬性

如想獲取當前時間前24小時,每隔半小時顯示一個隨機數。把下面獲得的data賦值給series中的data屬性即可
僞代碼:

let a = [];
let now = Date.parse(new Date()); //獲取當前時間戳
for (let i = 0; i < 48; i++) {
let A = Math.floor(Math.random() * (3000 - 800 + 1) + 800); //獲取隨機數,範圍800--3000
let times = now - i * 30 * 60 * 1000;
a.unshift([times, A]);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章