eChartsの動的タイムラインが表示される10秒前にデータが表示されないバグ修正メモ

echartsを使用して動的折れ線グラフ+時間軸を描画する場合、直近20秒以内のデータを表示する必要があるのですが、直近1分から最初の10秒間で描画不良が発生していることが判明しました。時間軸の時間要件は 2 桁の数値である必要があります。つまり、時/分/秒が 10 未満の場合は、先頭に「0」を追加する必要があります。そうしないと、レンダリングは最初の 10 秒で失敗します。

添付ファイル: タイムスタンプの対応する時間関数を取得します (ミリ秒までの精度)

getNowTime(timeStamp, milliSeconds?: number) {
    let date = new Date(timeStamp);
    let year = date.getFullYear();
    let month = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : "0" + date.getMonth() + 1;
    let day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
    let hour = date.getHours() > 9 ? date.getHours() : "0" + date.getHours();
    let minute =
      date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes();
    let second =
      date.getSeconds() > 9 ? date.getSeconds() : "0" + date.getSeconds();
    let currentTime = ""
    if(milliSeconds) {
      currentTime = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + 
        second +  "." + milliSeconds;
    } else {
      currentTime = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" +                             
        second;
    }
    return currentTime;
  }

おすすめ

転載: blog.csdn.net/weixin_46653941/article/details/123259084