score:0
Accepted answer
Reason your time axis is not working is because since chart.js V3 you will need to include your own date adapter, chart.js does not ship with a default date adapter anymore. For more information see the documentation
const data = {
datasets: [{
label: 'my first dataset',
borderColor: 'rgb(255, 99, 132)',
data: [{
x: "2016-12-25",
y: 3
}, {
x: "2016-12-28",
y: 10
}, {
x: "2016-12-29",
y: 5
}, {
x: "2016-12-30",
y: 2
}, {
x: "2017-01-03",
y: 20
}, {
x: "2017-01-05",
y: 30
}, {
x: "2017-01-08",
y: 45
}],
},
{
label: 'My Second dataset',
borderColor: 'rgb(99, 255, 132)',
data: [{
x: "2016-12-25",
y: 20
}, {
x: "2016-12-27",
y: 62
}, {
x: "2016-12-26",
y: 15
}, {
x: "2016-12-31",
y: 172
}, {
x: "2017-01-01",
y: 30
}, {
x: "2017-01-05",
y: 50
}, {
x: "2017-01-06",
y: 25
}],
}
]
};
const config = {
type: 'line',
data: data,
options: {
responsive: true,
scales: {
x: {
type: 'time',
}
}
},
};
const myChart = new Chart(
document.getElementById('line-chart'),
config
);
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chart.js Integration</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!--Line below added, added date adapter for time scale -->
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
</head>
<body>
<canvas id="line-chart" width="800" height="450"></canvas>
</body>
</html>
Source: stackoverflow.com
Related Query
- How to enable timescale in chart.js line chart?
- Chart.js - How to set a line chart dataset as disabled on load
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How to add an on click event to my Line chart using Chart.js
- Chart.js how to show cursor pointer for labels & legends in line chart
- How to display Line Chart dataset point labels with Chart.js?
- How to add second Y-axis for Bar and Line chart in Chart.js?
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- How to display value of only one datapoint in line chart
- How to align Chart.JS line chart labels to the center
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How can I remove extra whitespace from the bottom of a line chart in chart.js?
- How to create a gradient fill line chart in latest Chart JS version (3.3.2)?
- How to draw Horizontal line on Bar Chart Chartjs
- how to set chart.js grid color for line chart
- how to programmatically make a line chart point active/highlighted
- How to start the line graph from the left Y axis in a line/bar mixed chart (Chart.js)?
- How to dynamically set ChartJs line chart width based on dataset size?
- How to add gradient background to Line Chart [vue-chart.js]
- How to show data values in top of bar chart and line chart in chart.js 3
- How can I make line on chart thinner?
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- In Stacked horizontal bar chart how to remove the vertical line in Chart.js?
- How to add area with break on line chart with fill color
- How do I use my chart.js line chart with handlebars?
- How to plot a line chart in ChartJS?
- How to use segment property to color line / border color based on value in chart js?
- How to change the label and grid line position on a timeseries chart in Chart.js 3?
- How to make aspecific API call from within a Line Chart class in ReactJS using react-chartjs-2?
More Query from same tag
- Bars on second X Axis not showing
- Datalabels plugin chartjs showing '[object]' instead of value
- Chart.js minimal width of Chart with scrollable overflow
- How do I hide values past the x-axis in chartjs 2.0?
- Chart.JS removing data stuck in loop
- chart-options not registering scaleStartValue
- VueJS and dynamic reload ChartJS when screen resize
- ChartJS and Laravel5
- Uncaught ReferenceError: Chart is not defined in Laravel mix
- Change X and Y axis font color
- How scale sector in doughnut chartjs on hover?
- Parsing an unnamed JSON array into React component
- Which jquery plugin can create a stacked column chart?
- Chartjs barchart generate data for an array dataset
- Chart.js Doughnut chart inner label different than outer
- Chart Js clickable bar
- Assigning a value to an object w/bracket notation
- how to modify horizontal bar chart using chart js
- Time series data visualization using JSON
- chartjs: trying to rotate the y-Axis label
- How to have mutiple charts in a single page using Chart.js?
- loading json file to create chart
- Chart.js doughnut chart comes bigger and bigger
- ChartJs - Is is possible to show only tooltip in one dataset?
- ChartJS align bars to left instead of center
- How to add commas in thousands and to show decimal upto 2 places on X/Y axis in Angular chat JS?
- chart.js Line chart with different background colors for each section
- ChartJS does not render correctly
- Remove redundant legends on the chart using generateLabels with ChartJS v3
- in chart js tooltip font size is not working