简体   繁体   English

如何在clickgraphitem上获取amchart堆叠条的标签

[英]how to get label of amchart stacked bar on clickgraphitem

I want to get Label on graph click event,i am using amchart stacked bar.我想在图形点击事件上获得标签,我正在使用 amchart 堆叠条。

  • Example :例子 :
    • When I click on bar 1 graph 1 of category 1 : 8 , I get graph 1 .当我点击类别 1 的条形图 1 1 时: 8 ,我得到图 1
    • When I click on bar 1 graph 2 of category 1 : 5 , I get graph 2 .当我单击类别 1 的条形图 1图 2 时: 5 ,我得到图 2

Below is the link of chart and also I added my code: Stackbar chart .下面是图表的链接,我还添加了我的代码: Stackbar chart

chart.addListener("clickGraphItem", DashBoardClick); 
    function DashBoardClick(event) {
    alert(event.item.category);
}

Assuming you meant the title of the graph, you can access it through the graph object in the event argument as noted in the documentation and then access the graph's title property, ie event.graph.title .假设您的意思是图形的标题,您可以通过文档中提到的事件参数中的graph对象访问它,然后访问图形的title属性,即event.graph.title

 var chart = AmCharts.makeChart("chartdiv", { "type": "serial", "categoryField": "category", "startDuration": 1, "categoryAxis": { "gridPosition": "start" }, "trendLines": [], "graphs": [ { "balloonText": "[[title]] of [[category]]:[[value]]", "fillAlphas": 1, "id": "AmGraph-1", "title": "graph 1", "type": "column", "valueField": "column-1" }, { "balloonText": "[[title]] of [[category]]:[[value]]", "fillAlphas": 1, "id": "AmGraph-2", "title": "graph 2", "type": "column", "valueField": "column-2" } ], "guides": [], "valueAxes": [ { "id": "ValueAxis-1", "stackType": "regular", "title": "Axis title" } ], "allLabels": [], "balloon": {}, "legend": { "enabled": true, "useGraphSettings": true }, "titles": [ { "id": "Title-1", "size": 15, "text": "Chart Title" } ], "dataProvider": [ { "category": "category 1", "column-1": 8, "column-2": 5 }, { "category": "category 2", "column-1": 6, "column-2": 7 }, { "category": "category 3", "column-1": 2, "column-2": 3 } ] } ); chart.addListener('clickGraphItem', function(event) { alert(event.graph.title); })
 <script src="//www.amcharts.com/lib/3/amcharts.js"></script> <script src="//www.amcharts.com/lib/3/serial.js"></script> <script src="//www.amcharts.com/lib/3/themes/light.js"></script> <div id="chartdiv" style="width: 100%; height: 350px;"></div>

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

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