1

Following on from how to use zrender with vue-echarts to register clicks on bar chart

The example below does not work when the X-axis is of type time

For an x-axis of type time the .data property does not exist on the axis object.

chart.getZr().on('click', function(params){
  console.log(params)
  var pointInPixel = [params.offsetX, params.offsetY];
  var pointInGrid = chart.convertFromPixel('grid', pointInPixel);
  console.log(pointInGrid)
  var category = chart.getModel().get('xAxis')[0].data[pointInGrid[0]] // <-- bang!
  console.log(category)
})

I can get the time-continuum value (in milliseconds) but this extends over the whole canvas (not just the chart grid)

I cannot find a way to determine the following

  • If the time value is actually in the chart grid ?
  • What the closest dataset x-axis value is ?
Rob Shepherd
  • 866
  • 1
  • 9
  • 25

0 Answers0