jperezov
jperezov

Reputation: 3181

Highcharts trigger background click event

I'm using Highcharts to trigger an event when the background is clicked:

$("#my-chart").highcharts({
    chart: {
        type: "pie",
        events: {
            click: function() {
                console.log("I'm working!"); // This is the event I want to trigger
            };
        }
    }
 });
 var myChart = $("#my-chart").highcharts();

I would like to trigger this event when clicking on something outside of the chart. For example:

<button>Trigger the Highcharts Event!</button>
<script>
    $("button").on('click', function() {
        // I'd like to trigger the event here
        // $('#my-chart').click(); does nothing
        // myChart.chart.events.click(); does nothing
        // myChart.events.click(); does nothing
        // $('#my-chart').find('rect.highcharts-background').click() does nothing
    });
</script>

How can I trigger the event programmatically?


I've tried several things to get more information. Looking at arguments.callee.caller.name, the value is "" (empty string). arguments.callee.caller gives me the following:

function (a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}}

Ain't nobody got time to decipher that!

A bit more useful information is the event.target, which is rect.highcharts-background. Triggering a click on that does nothing. Absolutely nothing. I've made a few other attempts, all within the comments in the $('button').click() function above.

Upvotes: 0

Views: 1732

Answers (1)

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

You can add fireEvent function and then trigger this from the outside.

Example: http://jsfiddle.net/er90yeem/1/

Upvotes: 2

Related Questions