I'm new to vue and apex charts, basically what I need is to call a method from an apex chart option, I created a file showing the problem I'm having:
https://jsfiddle.net/wr3uo5va/
I need to call the method currencyValue
from
chartOptions.dataLabels
dataLabels: { enabled: true, offsetX: -25, formatter: function(val) { return val + " Reais"; <--- This works // return this.currencyValue(val) <--- This does not work }, },
Any suggestions?
You can put
chartOptions
in the method instead of the data. Below is the working codeMethods cannot be called in
data
orcompulated
, but can be called inmethods
One thing that needs to be modified is as follows
The problem is that
this
in theformatter
callback is the chart instance (not the component instance) because it is declared as a regular function.The solution is to use arrow functions to bind the component instance as context:
Updated fiddle