JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://chartjs.org/dist/master/chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-adapter-moment/0.1.2/chartjs-adapter-moment.min.js"></script>
<canvas id="chart" height="400px"></canvas>
JavaScript
var labels = ['One', 'Two', 'Three', 'Four', 'Five'];
var config = {
type: 'line',
data: {
yLabels: [5, 4, 3, 2, 1],
datasets: [{
borderWidth: 3,
showLine: true,
data: [{
x: new Date('2016-11-25'),
y: 2
},
{
x: new Date('2016-11-30'),
y: 3
},
{
x: new Date('2016-12-22'),
y: null
},
{
x: new Date('2017-02-12'),
y: 1
},
{
x: new Date('2017-04-01'),
y: 2
},
{
x: new Date('2017-04-21'),
y: 4
},
{
x: new Date('2017-05-01'),
y: 3
},
{
x: new Date('2017-06-30'),
y: 5
}
],
fill: false,
borderColor: 'red',
backgroundColor: 'red'
}]
},
options: {
scales: {
x: {
type: 'time',
min: new Date('2016-11-05'),
max: new Date('2017-08-01'),
time: {
unit: 'week',
isoWeekday: true
},
display: true,
grid: {
display: false
},
},
y: {
type: 'category',
position: 'left',
display: true,
ticks: {
callback: function(value) {
return labels[value - 1];
},
reverse: false // why are they reversed?
}
}
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
return labels[tooltipItem.yLabel - 1];
}
}
}
}
};
var cc = new Chart('chart', config);