1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Chart.js の時間軸を使おうとしてコケたところ

Posted at

大学院生の備忘録シリーズ 第二弾

Chart.jsの時間軸を使おうとしたらエラーを吐かれました

Uncaught Error: This method is not implemented: either no adapter can be found or an incomplete integration was provided

options.scales[scaleID]
type: 'time',
time: {
    unit:'day',
    displayFormats: {
        day: 'MM/DD'
    },
},

コード的には問題なさそう.type:'time'を外すとエラーなしに通る.

色々調べて参考にしたのは次のページ,全く同じ症状でした.

chart.js で TimeScale の使い方

どうやらchart.js単体では時間軸を扱えないらしい.

3.x Migration Guide #Setup and installation | Chart.js

公式ドキュメントにも書いてあった.

結論

時間を扱うライブラリーとadapterライブラリーを読み込まないといけないらしい.

今回はCDNを利用するのでMoment.jschartjs-adapter-momentのふたつをjsDelivrで検索してhtmlに貼り付けます.

    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.2/chart.min.js"></script>
    <script defer src="https://cdn.jsdelivr.net/combine/npm/moment@2.29.1,npm/chartjs-adapter-moment@1.0.0"></script>

無事使えるようになりました

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?