Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Bringing "this" into scope for the formatLabel function
posted

I'm trying to create a formatLabel function that can reach "this" in typescript.

This populates the labels with the correct date, but i need to reach a variable in the class to check the resolution so i can format the date accordingly.

formatLabel: function (value) {
   var d = new Date(value.Time);
   return d.getDate() + "/" + (d.getMonth()+1);
}

When i do this i successfully trigger the desired method and generate the correct string based on the resolution, but it fails to populate the labels in the chart.

formatLabel: ((value) => { this.formatSeriesLabel(value) })

formatSeriesLabel(value) {    

   switch (this.dataSource.Resolution) {
      case 7:
         var d = new Date(value.Time);
         return d.getHours().toString();
      case 20:
         var d = new Date(value.Time);
         return d.getDate() + "/" + (d.getMonth() + 1);
   }
}

Changing the method to just return a test string does not return properly either.

formatSeriesLabel(value){

   return "test";

}

Why isn't this populating the labels in the chart?

Parents Reply Children
No Data