【问题标题】:Get the H-Axis(X-Axis) value of google area chart获取谷歌面积图的H-Axis(X-Axis)值
【发布时间】:2014-08-27 14:12:25
【问题描述】:

在谷歌图表数据表对象中,我可以使用datatable.getValue(...) 获取当前选择点值(V 轴/Y 轴)。但是,如果我想从 X 轴获取时间/日期/年份(见屏幕截图)。我没有找到任何数据表的功能来实现这一点。有谁知道怎么做??

这是我的代码

google.visualization.events.addListener(chart, 'select', function(a, b, c, d) {
            var selectedItem = chart.getSelection()[0];
            if (selectedItem) {
              // Get the current Y-axis value which is 1120
              var value = data.getValue(selectedItem.row, selectedItem.column);
              alert('The user selected ' + value);
              // How I can get the value of 2015 which is the X-axis value??????
            }
        });

【问题讨论】:

    标签: javascript google-api google-visualization google-datatable


    【解决方案1】:

    在大多数情况下,您的轴值将在第 0 列,因此只需将 selectedItem.column 更改为 0,您将获得轴值:

    var axisValue = data.getValue(selectedItem.row, 0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多