需要工具提示:将Google表格现有数据更改为DataTable [英] Need Tooltips: Change google sheet existing data into DataTable

查看:118
本文介绍了需要工具提示:将Google表格现有数据更改为DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
我看到的所有文档都使用DataTable在脚本本身中写入数据。我需要从现有行中调用此工具提示数据。
我需要了解HTML页面和Google工作表中的嵌入式图表之间的代码差异。

Problem: All the documentation I see uses a DataTable that writes the data in the script itself. I need to call this tooltip data from existing rows. I need to understand the code difference between an HTML page and an embedded chart in a google sheet.

目标:
我有一个散点图,需要自定义工具提示。我需要将Q列中的数据显示为工具提示,使用以下代码以及工具提示将R和S列中的数据悬停在
插入图表上:

Goal: I have a scatter plot that needs custom tooltips. I need the data from column Q to show as the tooltip, on hover with the data in column R and S insert chart using this code plus tooltip:

    function newChart() {
  // Generate a chart representing the data in the range of A1:B15.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[11];

  var chart = sheet.newChart()
     .setChartType(Charts.ChartType.SCATTER)
     .addRange(sheet.getRange('R3:S5000'))
     .addRange(sheet.getRange('Q3:Q5000'))

     .setPosition(5, 5, 0, 0)
     .build();

  sheet.insertChart(chart);
}

-OR-

 function drawChart() {
        var dataTable = new google.visualization.DataTable();
        dataTable.addColumn('string', 'Year');
        dataTable.addColumn('number', 'Sales');
        // A column for custom tooltip content
        dataTable.addColumn({type: 'string', role: 'tooltip'});
        dataTable.addRows([
          ['2010', 600,'$600K in our first year!'],
          ['2011', 1500, 'Sunspot activity made this our best year ever!'],
          ['2012', 800, '$800K in 2012.'],
          ['2013', 1000, '$1M in sales last year.']
        ]);

        var options = {
          tooltip: {isHtml: true},
          legend: 'none'
        };
        var chart = new google.visualization.ColumnChart(document.getElementById('col_chart_html_tooltip'));
        chart.draw(dataTable, options);
      }

引用:
> https://developers.google.com/chart/interactive/docs/reference#DataView
< a href = https://developers.google.com/chart/interactive/docs/customizing_tooltip_content#tooltip-actions rel = nofollow noreferrer> https://developers.google.com/chart/interactive/docs/customizing_tooltip_content #tooltip-actions
https://developers.google。 com / chart / interactive / docs / spreadsheets

推荐答案

在嵌入式图表中,使用数据视图定义添加工具提示角色...

in the embedded chart, use a data view definition to add the tooltip role...

请参阅以下代码段...

see following snippet...

function newChart() {
  // Generate a chart representing the data in the range of A1:B15.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[11];

  // build the data view definition
  var COLUMN_SPEC = [
    0,
    1,
    {sourceColumn: 2, role: 'tooltip'}
  ];
  var viewSpec = Charts.newDataViewDefinition()
     .setColumns(COLUMN_SPEC)
     .build();

  var chart = sheet.newChart()
     .setChartType(Charts.ChartType.SCATTER)
     .setDataViewDefinition(viewSpec)
     .addRange(sheet.getRange('R3:S5000'))
     .addRange(sheet.getRange('Q3:Q5000'))

     .setPosition(5, 5, 0, 0)
     .build();

  sheet.insertChart(chart);
}

这篇关于需要工具提示:将Google表格现有数据更改为DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆