如何在谷歌图表中获取传奇寻呼信息?

时间:2016-08-24 14:13:29

标签: google-visualization

我需要获取传说的分页信息。如下图所示,我们有legends.so的分页,我们需要获取当前选择的页面和页面信息的数量。 click here for image

1 个答案:

答案 0 :(得分:0)

因为没有配置选项,
你必须检查包含信息的SVG元素,
一旦'ready'事件触发

请参阅以下工作代码段...

google.charts.load('current', {
  callback: function () {
    var container = document.getElementById('chart_div');
    var chart = new google.visualization.PieChart(container);
    var message = document.getElementById('msg_div');

    google.visualization.events.addListener(chart, 'ready', getLegendPage);
    google.visualization.events.addListener(chart, 'select', getLegendPage);

    function getLegendPage() {
      Array.prototype.forEach.call(container.getElementsByTagName('text'), function(text) {
        if (text.getAttribute('text-anchor') === 'middle') {
          var legendPages = text.innerHTML.split('/');
          message.innerHTML = 'Selected Legend page is ' + legendPages[0] + ' of ' + legendPages[1];
        }
      });
    }

    chart.draw(google.visualization.arrayToDataTable([
      ['Task', 'Hours'],
      ['A', 19.2],
      ['B', 30.8],
      ['C', 50.0],
      ['D', 19.2],
      ['E', 30.8],
      ['F', 50.0],
      ['G', 19.2],
      ['H', 30.8],
      ['I', 50.0],
      ['J', 19.2],
      ['K', 30.8],
      ['L', 50.0],
      ['M', 19.2],
      ['N', 30.8],
      ['O', 50.0]
    ]), {
      height: 400,
      chartArea: {
        top: 24
      },
      legend: 'top',
      pieHole: 0.4,
      width: 400
    });
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
<div id="msg_div"></div>