1

I'm modifying some examples [1][2] to draw a line on the canvas. For the end-point I have calculated a data value but now I want to calculate the y value on the canvas. In the examples I found

this.chart.chart.scale.getPixelForValue()

which seems deprecated in chart.js 2.6

// Used to get data value locations.  Value can either be an index or a numerical value
getPixelForValue: helpers.noop,

The first example uses

this.calculatePointY()

but that doesn't help me either.

What would I use instead?

[Note]: This question is similar but has no answers: Get Y value of line from X pixel value in ChartJS 2

[1] https://stackoverflow.com/a/39118152

[2] https://stackoverflow.com/a/37222238

Foppe
  • 301
  • 1
  • 6

1 Answers1

2

For ChartJS - version 2.6, you should use the following ...

chart.scales['y-axis-0'].getPixelForValue(<value>);
ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110