I have a simple line chart with 5 labels on x-axis: 'Oct 2018', 'Jan 2019', 'Apr 2019', 'Jul 2019', 'Oct 2019'
and a line which has points only on 3 middle labels 'Jan 2019', 'Apr 2019', 'Jul 2019'
.
The problem is that when line data doesn't start from first label (like in my case), the tooltip shows incorrect label on hover. As you can see from below image, when I hover on 'Apr 2019'
data point, tooltip shows 'Jan 2019'
. Similarly, when I hover on 'Jul 2019'
data point, tooltip shows 'Apr 2019'
. Can you tell me what am I missing?
Here's the code:
<canvas id="canvas" ></canvas>
<script>
var lineChartData = {
labels: ['Oct 2018', 'Jan 2019', 'Apr 2019', 'Jul 2019', 'Oct 2019'],
datasets: [
{
label: 'Oranges',
borderColor: window.chartColors.blue,
backgroundColor: window.chartColors.blue,
fill: false,
data:
[
{y: 30, x: 'Jan 2019'},
{y: 20, x: 'Apr 2019'},
{y: 25, x: 'Jul 2019'},
],
}
]
};
window.onload = function() {
var ctx = document.getElementById('canvas').getContext('2d');
window.myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
responsive: true,
hoverMode: 'index',
stacked: false,
scales: {
yAxes: [{
type: 'linear',
display: true,
position: 'left'
}],
}
}
});
};
</script>