简体   繁体   English

如何处理AmCharts股票图上的点击事件?

[英]How to handle click event on AmCharts Stock graph?

I'm trying to do it using amStockCharts v3. 我正在尝试使用amStockCharts v3做到这一点。 I've seen this question: here , but it doesn't seems to work with Stock charts. 我已经看到了这个问题: 在这里 ,但是它似乎不适用于股票图表。

How can I handle click event for this chart - http://www.amcharts.com/demos/multiple-data-sets/ ? 如何处理此图表的点击事件-http: //www.amcharts.com/demos/multiple-data-sets/ I need to be able to get date and value corresponding to a clicked point. 我需要能够获取与单击的点相对应的日期和值。

As you can see here the stockchart itself does not support click events on the graph or items. 正如你可以看到这里的stockchart本身支持图形或项目单击事件。
However, you can solve this by adding listeners to single panels. 但是,您可以通过将侦听器添加到单个面板来解决此问题。 (see docs ) (请参阅docs
As the panels are initialized after the chart chart.panels[x].addListener() won't work. 由于面板是在图表chart.panels[x].addListener()之后初始化的,因此将不起作用。
Instead you have to wrap it in the charts init event like this: 相反,您必须将其包装在图表init事件中,如下所示:

chart.addListener("init", function () {
    for( var x in chart.panels ) {
        chart.panels[x].addListener("clickGraphItem", function(e) {
            alert("index: "
                    + e.item.index
                    + "\nvalue: "
                    + e.item.values["value"]); //valuefield depends on your mapping!!!
        });
    }
});

Important for "clickGraphItem" is, that there must be an actual item to be clicked on. 对于“ clickGraphItem”而言,重要的是必须要单击一个实际的项目。 In other words there must be a bullet. 换句话说,必须有一颗子弹。 If you don't want them to be seen, just set their alpha to zero. 如果您不希望看到它们,只需将其alpha设置为零即可。

bullet: "round",
bulletAlpha: 0

You can play around with the shape and size of the bullets, to change the click area. 您可以试一下子弹的形状和大小,以更改单击区域。
I prepared a fiddle for you. 我为你准备了一个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM