Time scales
You can use simple string categories to represent dates and temporal information, but by using an axis of the time type, you can parse, format, and generate temporal data. This allows greater flexibility and interactivity.
The time scale requires the moment.js
library (momentjs.com). To use the time scale, you can either import the moment.js
library or include the Chart.bundle.js
library in your page. It's best to import moment.js
since you might want to use other date and time functions. You can do that including by it in your page via CDN:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.js"> </script>
The data is usually configured using the point structure, where the x property is a Date and the y property is some quantitative value. You can also use the t property instead of x. Many standard date formats are parsed automatically. These are some valid data points for time:
{x: new Date(), y: 1} // now {t: ‘20190224’, y: 2} // 2019-02-24...