2016-12-06 51 views
0

我试图操纵图例中显示的值,同时用ChartCursor悬停在图表上(我已经连接了一个侦听器函数,但似乎无法找到每个对象是否显示在图例各电流值):AmCharts:如何访问在图例中显示的值

enter image description here

我试图与valueText访问使用

chart.legend.valueText 

但是,如果我更换valueText将发生的值设定在每一个对象传说。我希望能够触及图例中的每个对象,并且能够操作每个对象的valueText。

监听器在chartCursor实现:

"chartCursor": { 
     "categoryBalloonEnabled": false, 
     "listeners": [{ 
      "event": "changed", 
      "method": cursorChanged 
     }] 
     }, 

是否有人知道如何做到这一点?

谢谢。

回答

1

要访问图例值,你必须创建一个valueFunction传说对象中:

"legend": { 
     // ... 
     "valueFunction": function(graphDataItem, valueText) { 
      //check if valueText is empty. 
      //this only occurs when you're not currently hovered over a value 
      //and if you don't have a periodValueText set. 
      if (valueText !== " ") { 
      //access the current graph's value through the graph.valueField 
      //inside the graphDataItem parameter, 
      //or the string version of the value in valueText and manipulate it accordingly 
      return graphDataItem.dataContext[graphDataItem.graph.valueField]; //current hovered value 
      } else { 
      return valueText; 
      } 
     } 
    }, 

valueFunction称为该具有可见图例标记每个图形对象。

Demo

相关问题