0

I want to call a function from plotoptions of highcharts i tried like this but its throwing error

plotOptions: {
                series: {
                    events: {
                        legendItemClick: function(event) {
                        //iam trying to call a function here
                        sampletest(testArr);

                        }
                    }
                }
            }

is this possible..how to call another function from plotOptions.

the error iam getting is

TypeError: d is undefined

3
  • thats type error..it is TypeError: d is undefined Commented May 9, 2013 at 13:00
  • 1
    Can you post the code for your sampletest function ? It is possible that the error is in that function rather than in the legendItemClick function. Commented May 9, 2013 at 13:48
  • I Went wrong in the sampletest function only..at the end its building again the chart..thats the reason iam getting error. Commented May 10, 2013 at 10:14

3 Answers 3

1

You can use a IIFE for that. This example is when the function y external of the chartOption{}

plotOptions: {
    series: {
        point: {
            events: {
                click: (function (integrator) {
                    return function (e: any) {
                        integrator.externalFunction()
                    }
                })(this)
            }
        }
    }
}

function externalFunction() {
    console.log('Prueba funcion externa');
}
Sign up to request clarification or add additional context in comments.

Comments

0

yes you can call any function from plotoptions events. Highcharts allows us to do so. just check the scope of that function

2 Comments

thanks for reply strikers..what should be the scope of the function?
What do you mean by "check the scope of that function"? A JS function has its own scope. if you mean context than: why would you have to check the scope? just Bind if needs must
0

Please take look at example http://jsfiddle.net/gF8Cf/3/

    $(function () {
    $('#container').highcharts({
        plotOptions: {
            series: {
                cursor: 'pointer',
                events: {
                    click: function(event) {
                       custom();
                    }
                }
            }
        },

        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
        }]
    });

    function custom(){
        alert('aaaa');
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.