How to draw 2 datasets on the same Chart.js plot, but with different sizes?
- one line is for daily points
- the second line has points every 6 hours, i.e. 4 x more points
This doesn't work:
const ctx = document.getElementById('myChart').getContext('2d');
const data = {
labels: ["mon", "tue", "wed", "thu"],
datasets: [{
label: 'daily',
data: [65, 59, 80, 81],
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}, {
label: 'every 6 hours',
data: [60, 61, 62, 61, 58, 57, 66, 44, 81, 87, 99, 13, 81, 80, 79, 78],
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
};
const myChart = new Chart(ctx, {
type: 'line',
data: data,
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
In this codepen I randomly found it nearly works but I don't think it's the standard way,because when you hover one red bar, it shows the tooltip as expected, but also shows the tooltip for a distant unrelated point, which is not good.
Note: I have already read ChartJS - Line Chart with different size datasets but the result is not good (see the answer's screenshot's x-axis which is unreadable).