Calling Typescript function from Highcharts load event

The Hungry Dictator

I am trying to call typescript function openDialog() from the events.load of highcharts but I am not able to call it. Even though I am using arrow function I am not able to get it. Here is my code :

events: {
    load: () => {
       var chart : any = this;
      for (var j in chart.series) {
        var series = chart.series[j];
        for (var i in series.data) {
          ((i) =>{
            var point = series.data[i];
            if (point.graphic) {
              point.graphic.on('click',(e)=>this.openDialog(point.options,'all')
            );
            }
          })(i)
        }
      }
    }
  },


  public openDialog(option,type){
       //Do Something
  }

EDIT

I have got one link where there are binding this with function.

Is there anything that I am missing ?

The Hungry Dictator

Finally got it worked by this simple change

events: {
  load: function(e) {
   var chart : any = e.target; // to get the chart details
  for (var j in chart.series) {
    console.log(j)
    var series = chart.series[j];
    for (var i in series.data) {

      ((i) =>{
        console.log(i)
        var point = series.data[i];
        if (point.graphic) {
          point.graphic.on('click',(e)=>this.openDialog()
        );
        }
      })(i)
    }
  }
  }.bind(this) //binding the parent this to access openDialog function
},


public openDialog(option,type){
   //Do Something
}

Here I had to bind this which does not comes from chart. So I have to bind this using .bint(this) to the load function. And to get the chart details I am using e.target. This way I am getting it worked.

Stackblitz Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a function from another function in typescript

From Dev

calling function from programmatically created button event

From Dev

Calling function from HTML to typescript not waited to finish

From Dev

Javascript prototype function calling from typescript

From Dev

Calling function on load of function

From Dev

Calling a typescript method from your html button onclick event

From Dev

Calling a KeyDown Event on Form Load

From Dev

Calling "unknown" function in typescript

From Dev

Calling a TypeScript function in HTML?

From Dev

Backbone.js calling function render from event handler

From Dev

javascript function not calling from code behind when i'm calling another function within same click event

From Dev

how to add extra labels at load event in highcharts

From Dev

Calling Typescript function from html2canvas in angular 2

From Dev

Calling typescript function from HTML using a module system

From Dev

Calling native function from TypeScript in react-native

From Dev

React typescript passing function as prop and calling from child component

From Dev

Calling D3.JS function on 'load' rather than on mouse event

From Dev

Call UserControl function from Page's Page_Load event

From Dev

Calling a function from a function

From Dev

Calling paint event inside a function

From Dev

Calling a JS function by event emitting

From Dev

Event dispatcher calling code function

From Dev

Function is not calling on onclick event in React

From Dev

Javascript - Calling a function for an onClick event

From Dev

Calling a typescript function named in a variable

From Dev

Calling an object function if it exists in TypeScript

From Dev

How to attach click event function in Highcharts

From Dev

how to load sub category based on category by calling jquery function from <td> of javascript function for adding rows dynamically?

From Dev

Calling a function from data()

Related Related

  1. 1

    Calling a function from another function in typescript

  2. 2

    calling function from programmatically created button event

  3. 3

    Calling function from HTML to typescript not waited to finish

  4. 4

    Javascript prototype function calling from typescript

  5. 5

    Calling function on load of function

  6. 6

    Calling a typescript method from your html button onclick event

  7. 7

    Calling a KeyDown Event on Form Load

  8. 8

    Calling "unknown" function in typescript

  9. 9

    Calling a TypeScript function in HTML?

  10. 10

    Backbone.js calling function render from event handler

  11. 11

    javascript function not calling from code behind when i'm calling another function within same click event

  12. 12

    how to add extra labels at load event in highcharts

  13. 13

    Calling Typescript function from html2canvas in angular 2

  14. 14

    Calling typescript function from HTML using a module system

  15. 15

    Calling native function from TypeScript in react-native

  16. 16

    React typescript passing function as prop and calling from child component

  17. 17

    Calling D3.JS function on 'load' rather than on mouse event

  18. 18

    Call UserControl function from Page's Page_Load event

  19. 19

    Calling a function from a function

  20. 20

    Calling paint event inside a function

  21. 21

    Calling a JS function by event emitting

  22. 22

    Event dispatcher calling code function

  23. 23

    Function is not calling on onclick event in React

  24. 24

    Javascript - Calling a function for an onClick event

  25. 25

    Calling a typescript function named in a variable

  26. 26

    Calling an object function if it exists in TypeScript

  27. 27

    How to attach click event function in Highcharts

  28. 28

    how to load sub category based on category by calling jquery function from <td> of javascript function for adding rows dynamically?

  29. 29

    Calling a function from data()

HotTag

Archive