score:1

Accepted answer

you can use a custom label callback for this to get the correct data for the tooltip:

<!doctype html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.4/chart.js"></script>

<body>
  <canvas id="mychart" style="width:100%;max-width:700px"></canvas>

  <script>
    var xyvalues = [{
        x: "march",
        y: 15
      },

    ];

    new chart("mychart", {
      type: "scatter",
      data: {
        datasets: [{
          pointradius: 4,
          pointbackgroundcolor: "rgb(0,0,255)",
          data: xyvalues
        }]
      },
      options: {
        tooltips: {
          callbacks: {
            label: (ttitem, data) => (`(${data.datasets[ttitem.datasetindex].data[ttitem.index].x}, ${data.datasets[ttitem.datasetindex].data[ttitem.index].y})`)
          }
        },
        legend: {
          display: false
        },
        scales: {
          xaxes: [{
            type: 'category',
            labels: ['january', 'february', 'march', 'april', 'may', 'june']
          }],
          yaxes: [{
            ticks: {
              min: 6,
              max: 16
            }
          }],
        }
      }
    });
  </script>

</body>

</html>

edit:

you can also choose to update to the latest major version of chart.js (version 3), there this behaviour seems to be fixed by default.

there are some major breaking changes in v3 like how scales are defined, now all scales are their own object for example with the scale id being the object key. for all changes you can read the migration guide

<!doctype html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.6.0/chart.js"></script>

<body>
  <canvas id="mychart" style="width:100%;max-width:700px"></canvas>

  <script>
    var xyvalues = [{
        x: "march",
        y: 15
      },

    ];

    new chart("mychart", {
      type: "scatter",
      data: {
        datasets: [{
          pointradius: 4,
          pointbackgroundcolor: "rgb(0,0,255)",
          data: xyvalues
        }]
      },
      options: {
        plugins: {
          legend: {
            display: false
          }
        },
        scales: {
          x: {
            type: 'category',
            labels: ['january', 'february', 'march', 'april', 'may', 'june']
          },
          y: {
            min: 6,
            max: 16
          },
        }
      }
    });
  </script>

</body>

</html>

score:0

just give january and february a null value.

<!doctype html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.4/chart.js"></script>
<body>
<canvas id="mychart" style="width:100%;max-width:700px"></canvas>

<script>
var xyvalues = [
  null, null,
  {x:"march", y:15},
];

new chart("mychart", {
  type: "scatter",
  data: {
    datasets: [{
      pointradius: 4,
      pointbackgroundcolor: "rgb(0,0,255)",
      data: xyvalues
    }]
  },
  options: {
    legend: {display: false},
    scales: {
      xaxes: [{ type: 'category', labels: ['january', 'february', 'march', 'april', 'may', 'june'] }],
      yaxes: [{ticks: {min: 6, max:16}}],
    }
  }
});
</script>

</body>
</html>


Related Query

More Query from same tag