chart.js API returns bad x and y points

182 views Asked by At

I am calling my bubbleChart via chart.js API and trying to access x,y values of points but I get this very strange behavior

console.log(bubbleChart._metasets[1].data)
console.log(bubbleChart._metasets[1].data[0])

enter image description here

when I access object.x or object.y I get those 350.017 and 537.199 for every point even in console it shows x,y with correct values. What is going on?

of course I tried also this, but same result

bubbleChart.getDatasetMeta(1).data[0]

here is the fiddle which show strange behavior console.log shows always same data for different endpoints but if you put in console bubbleChart._metasets it shows correct x,y values

https://jsfiddle.net/vxb792pe/

1

There are 1 answers

0
Mi Ro On

actually I found a workaround

var xAxis = bubbleChart.scales['x'];
var yAxis = bubbleChart.scales['y'];

pointx = xAxis.getPixelForValue(bubbleChart.data.datasets[i].data[0].x)
pointy = yAxis.getPixelForValue(bubbleChart.data.datasets[i].data[0].y)