score:12
Accepted answer
you need to add a date adapter as provided in the 3.x migration guide
(search in the page for "available adapters")
https://www.chartjs.org/docs/latest/getting-started/v3-migration.html
here is a working example
const data = {
labels: [
new Date(86400000), // Day 1
new Date(2 * 86400000), // Day 2
new Date(3 * 86400000), // Day 3
new Date(4 * 86400000), // Day 4
new Date(6 * 86400000), // Day 6
new Date(7 * 86400000), // Day 7
new Date(13 * 86400000), // Day 13
],
datasets: [
{
label: "My First dataset",
data: [1, 3, 4, 5, 6, 7, 8],
},
],
};
let ctx = document.querySelector("canvas").getContext("2d");
let chart = new Chart(ctx, {
type: "line",
data: data,
options: {
scales: {
x: {
type: "time",
}
},
},
});
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.27.0"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@0.1.1"></script>
<title>repl.it</title>
</head>
<body>
<canvas></canvas>
<script src="new.ts"></script>
</body>
</html>
Source: stackoverflow.com
Related Query
- Line graph with linear timescale in Chart.js
- Chart Js update legend boxes of graph with graph line style
- Single point on multiple line linear graph with Chart.js
- How to plot a single value with line in line chart graph using charts.js?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Chart.js - Plot line graph with X , Y coordinates
- line chart with {x, y} point data displays only 2 values
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chart.js - line chart with two yAxis: "TypeError: yScale is undefined"
- How to display Line Chart dataset point labels with Chart.js?
- Chart.js Mixed Bar and Line chart with different scales
- chart.js Line chart with different background colors for each section
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- Chart.js: Line chart with partial dashed line
- Obtain max value of y axis of line chart rendered with Chart.js
- ChartJS - Line Chart with different size datasets
- Line chart with large number of labels on X axis
- ChartJS - Line chart issue with only 1 point
- ChartJs line chart - display permanent icon above some data points with text on hover
- Chart.js - Bar chart with linear cartesian (numerical) X axis?
- Is it possible to revert x-axe values in line chart with chart.js
- Drawing line chart in chart.js with json response
- Chart.js with dual axis on bar and line graph
- Chart.js line chart with area range
- Chartjs line graph dataset with offset
- Extending Line Chart with custom line
- Can we draw a Line Chart with both solid and dotted line in it?
- Chart.js - Plot line graph with X , Y coordinates and connected by line
More Query from same tag
- Angular6 and ng2-charts does not display any charts when i fill data from webservice
- How to show bar chart labels clearly using ChartJS?
- Meteor / React.js / Chart.js issue
- How do I scrape data in <canvas> element with python or javascript?
- Chart.js 2.x animation onComplete not responding
- How to convert pandas dataframe to specific json format
- JQuery insertAfter() Method only works once when inserting a Chart.js chart
- Chart.js Picture inside doughnut segment
- When I try to include the chart.js and angular chartjs files, I get: ReferenceError: require is not defined
- Can I plot random points on a chart.js or Google Charts chart?
- ChartJS showing old values when mouse over on Doughnut after updating values
- Chart.js is always increasing height on chart.resize()
- Chart JS flicker when new data is added to chart (Vue)
- Filtering labels to show user from Chart.js
- ChartJS incorrect plot when plotting multiple line charts in one graph
- Chart.js - Setting x-axis based on user input
- Is it possible to have a decimal X axis for a line graph?
- Pass data from array to function vue
- How to maintain chartjs / ng2-charts gradient on window resize?
- how to use vuechartkick in nuxt js
- How Do I Properly Install/Access Javascript Library
- How to properly use the chartjs datalabels plugin
- Is there anyway to remove the dots for points from angularjs charts
- Switch chart.js data with button click
- Angular PrimeNG Chart Module: Customize hover text
- Chart.js legend - split into two and display separately?
- ChartJS Pie Chart How default just show 2 legend datas
- How can I add background color of length bars in chart (chartJS)?
- How to disable canvas elements from hijacking mouse wheel when scrolling through a page?
- How can I change the background colors of a bar chart after it has been created?