我在下面的代码中使用Google的图表可视化库。 当前,我有一个selectHandler函数,它为列行返回警报。

我正在尝试实现一些Javascript,而不是针对列号的警报,该警报发送以下所示项目“键”的警报。 我怎么得到这个?

<% @frequency.each do |key,value| %>
    ['<%= key %>', <%= value %>],
   <% end %>    

Java脚本

<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);

  function drawChart() {

      // OPTIONS
        var options = {
        title: 'Most common phrases in pro-Microsoft Reviews (<%= @reviews.count %> reviews analyzed)',
        vAxis: {title: 'Phrases',  titleTextStyle: {color: 'red'}},
        tooltip: {isHtml: true},
        animation:{
           duration: 2000,
           easing: 'out',
        }
      };

      // DATA
      var data = google.visualization.arrayToDataTable([
        ['Phrase', 'Frequency'],
            <% @frequency.each do |key,value| %>
                ['<%= key %>', <%= value %>],
               <% end %>
      ]);

      // CHART DRAWING
      var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
      chart.draw(data, options);
      google.load("visualization", "1", {packages:["corechart"]});
        google.setOnLoadCallback(drawChart);

      //setup listener
      google.visualization.events.addListener(chart, 'select', selectHandler);

      // The select handler. Call the chart's getSelection() method
       function selectHandler() {
          var selection = chart.getSelection();
          alert('That\'s column no. '+selection[0].row);
      }



  }


</script>

===============>>#1 票数:1 已采纳

我在下面的代码中使用Google的图表可视化库。 当前,我有一个selectHandler函数,它为列行返回警报。

我正在尝试实现一些Javascript,而不是针对列号的警报,该警报发送以下所示项目“键”的警报。 我怎么得到这个?

<% @frequency.each do |key,value| %>
    ['<%= key %>', <%= value %>],
   <% end %>    

Java脚本

<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);

  function drawChart() {

      // OPTIONS
        var options = {
        title: 'Most common phrases in pro-Microsoft Reviews (<%= @reviews.count %> reviews analyzed)',
        vAxis: {title: 'Phrases',  titleTextStyle: {color: 'red'}},
        tooltip: {isHtml: true},
        animation:{
           duration: 2000,
           easing: 'out',
        }
      };

      // DATA
      var data = google.visualization.arrayToDataTable([
        ['Phrase', 'Frequency'],
            <% @frequency.each do |key,value| %>
                ['<%= key %>', <%= value %>],
               <% end %>
      ]);

      // CHART DRAWING
      var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
      chart.draw(data, options);
      google.load("visualization", "1", {packages:["corechart"]});
        google.setOnLoadCallback(drawChart);

      //setup listener
      google.visualization.events.addListener(chart, 'select', selectHandler);

      // The select handler. Call the chart's getSelection() method
       function selectHandler() {
          var selection = chart.getSelection();
          alert('That\'s column no. '+selection[0].row);
      }



  }


</script>

  ask by sharataka translate from so

未解决问题?本站智能推荐: