Highcharts - fire legendItemClick事件 [英] Highcharts - fire legendItemClick event

查看:1365
本文介绍了Highcharts - fire legendItemClick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在您选择项目图例但从外部html按钮触发相同的事件。可以吗?

I want to fire the same event that it's fired when you select an item legend but from an external html button. Is it possible?

我创建了一个jsfiddle来显示它: http: //jsfiddle.net/YcJF8/1/

I've created a jsfiddle to show it: http://jsfiddle.net/YcJF8/1/ .

$('#container').highcharts({
                    chart : {
                        type : 'spline',
                    },

                    xAxis : {
                        categories : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
                    },

                    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],

                    }],

                    plotOptions : {
                        series : {

                        cursor : 'pointer',
                    }
                },
});

$('#button').click(function() {
        alert("Fire legenditemclick event");
});

在这个jsfiddle中,我有一个按钮,当我点击按钮时它会触发一个事件或者图表检测到的东西或类似物品图例(系列1)的动作被点击。

In this jsfiddle, I have a button and I want that when I click the button it fires an event or something that chart detects and acts like item legend (series 1) was clicked.

非常感谢

推荐答案

只需使用:

$($('.highcharts-legend-item')[0]).click()

0 是您希望点击的系列的索引。

Where the 0 is the index of the series you wish to 'click'.

更新小提琴

EDITS


  • highcharts-legend -item 是图例中每个条目的类。

  • $('。highcharts-legend-item')是一个jquery selector返回该类的所有元素的数组。我通过索引选择第一个,并将 $()将其转换为jQuery对象

  • .click 是这样的: http://api.jquery.com/click/

  • highcharts-legend-item is the class of each entry in the legend. I discovered this by inpecting the legend using chrome developer tools.
  • the $('.highcharts-legend-item') is a jquery selector to return an array of all elements of that class. I select the first one by index and the $() it to convert it into a jquery object
  • The .click is this: http://api.jquery.com/click/

这篇关于Highcharts - fire legendItemClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆