2017-09-26 1 views
1

그래프 클릭 이벤트에서 라벨을 가져오고 싶습니다. 저는 amchart 스택 막대를 사용하고 있습니다.클릭 그래프에서 누적 막대 그래프를 얻는 방법

  • 예 :
    • 내가 바 1 그래프 카테고리 1의 1을 클릭 : 8, 나는 그래프 1를 얻을.
    • 카테고리 1의 그래프 2를 클릭하면이고, 그래프 2이됩니다.

다음은 차트의 링크이며, 또한 나는 내 코드 추가 : Stackbar chart합니다. 당신이 그래프의 제목을 의미 가정

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

답변

1

, 당신은 documentation에서 언급 한 바와 같이 이벤트 인수에 객체를 통해 액세스 한 다음 그래프의 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>

관련 문제