JavaScript - Chart.js tooltip shows wrong x-axis value

前端 未结 3 1156
滥情空心
滥情空心 2021-01-20 05:16

I have a chart with two different datasets, but sometimes they have the same x, y coordinates. But when I hover a shared point, it sometimes shows the wrong date. T

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 05:50

    You defined a custom scale for a category cartesian axis in your chart configuration. Set the type for your xAxes to 'category'. This may not be neccessary as ChartJS picks this up by default.

    options: {
        scales: {
            xAxes: [{
                type: 'category',
                ....
    

    Also, the second data set isn't formatted properly. You should supply the data points in {x: xval, y: yval} format.

    References:

    http://www.chartjs.org/docs/latest/axes/cartesian/time.html#time-cartesian-axis

提交回复
热议问题