Hide specific legend in Google Chart

亡梦爱人 提交于 2019-12-24 21:55:20

问题


I have written code for Area Chart which has the functionality to hide the corresponding area if I click on a particular label, similar to this code.

The problem is if I click on a particular legend, the corresponding area and ALL legends are getting hidden. This is happening because I am doing,

var options = {legend: 'none'}; 

Is there a way that I can hide only the clicked legend (along with the corresponding area)?


回答1:


Your code is trying to hide the whole legend, not an area in the chart based on a click in a legend.

Trying looking at this code: http://jsfiddle.net/asgallant/6gz2Q - you basically need to create your chart in a specific way and add an on select listener to catch the event when the legend is clicked:

google.visualization.events.addListener(chart, 'select', function(){
   ...
});

Please note, the code in the example link is not mine, but it helped me with the same exact problem.



来源:https://stackoverflow.com/questions/23609797/hide-specific-legend-in-google-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!