获取点击柱形图的图例

Get the legend of clicked column chart

function selectHandler(e){
        var selectedItem = test.getSelection()[0];
        if (selectedItem.row != null) {
            // gets the location in x axis
            var loc_bar = data.getValue(selectedItem.row, 0);
          var value = data.getValue(selectedItem.row, selectedItem.column);
          debugger
          alert('The user selected ' + value);
        }
      }

这是我的 select 处理程序,在单击条形图时触发。我有一个堆积条形图,我想知道与单击的堆积条形图相关的图例。我发现了一个与饼图相关的 Whosebug link 但它对我没有帮助。那么有没有办法在单击 google 图表的堆叠条形图的一部分时获取图例?

使用 getColumnLabel 查找所单击列的图例名称...

var test = new google.visualization.ComboChart(document.getElementById('chart_div'));

google.visualization.events.addListener(test, 'select', selectHandler);
function selectHandler(e) {
  var selection = test.getSelection();
  if (selection.length > 0) {
    console.log('the user selected ' + data.getColumnLabel(selection[0].column));
  }
}

test.draw(data, options);