【问题标题】:Google Interactive Charts with images as custom html tooltip带有图像的 Google 交互式图表作为自定义 html 工具提示
【发布时间】:2015-09-24 02:21:04
【问题描述】:

好的,我对这方面真的很陌生,所以请多多包涵。我正在尝试使用来自网络上其他来源的图像的自定义 HTML 工具提示创建一个 Google 交互式折线图。但我不能让它工作;它甚至不会出现。这是我目前所拥有的(由developers.google.com 指导):

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi">    </script>
    <script type="text/javascript">

      // Load the Visualization API and the chart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table, 
      // instantiates the chart, passes in the data and
      // draws it.
      function drawChart() {

      // Create the data table.
      var dataTable = new google.visualization.DataTable();
      dataTable.addColumn('string', 'Date');
      dataTable.addColumn('number', 'Slices');
      dataTable.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});
      dataTable.addRows([
        ['January 1, 2015', 3, '<img width=100px src="https://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg">'],
        ['January 2, 2015', 2, '<img width=100px src="https://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg">'],
        ['January 3, 2015', 5, '<img width=100px src="https://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg">'], 
        ['January 4, 2015', 4, '<img width=100px src="https://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg">'],
        ['January 5, 2015', 2, '<img width=100px src="https://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg">']
      ]);

      // Set chart options
      var options = {
                     tooltip. {isHtml: true},
                     focusTarget: 'category',
                     'title':'How Much Pizza I Ate',
                     'width':900,
                     'height':400,
                     legend: { position: 'bottom' }
    };

      // Instantiate and draw our chart, passing in some options.
      var chart = new   google.visualization.LineChart(document.getElementById('chart_div'));
      chart.draw(dataTable, options);
    }
    </script>
  </head>

我知道我可能做错了什么。我会很感激有人的帮助。谢谢!

【问题讨论】:

    标签: javascript charts google-visualization


    【解决方案1】:

    这是一个错误:

     tooltip. {isHtml: true}
    

    应该是:

     tooltip: {isHtml: true}
    

    如果这不能解决问题,还可以尝试将回调移动到负载中:

    google.load('visualization', '1', {"callback" : drawChart, 'packages': ["corechart"]});
    //google.setOnLoadCallback(drawChart);
    

    【讨论】:

      猜你喜欢
      • 2015-02-19
      • 1970-01-01
      • 2019-11-20
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 2018-09-16
      相关资源
      最近更新 更多