gpt4 book ai didi

google-apps-script - 需要工具提示 : Change google sheet existing data into DataTable

转载 作者:行者123 更新时间:2023-12-05 06:29:20 38 4
gpt4 key购买 nike

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

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

    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);
}

-或-

 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 https://developers.google.com/chart/interactive/docs/customizing_tooltip_content#tooltip-actions https://developers.google.com/chart/interactive/docs/spreadsheets

最佳答案

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

请看下面的片段...

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-apps-script - 需要工具提示 : Change google sheet existing data into DataTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53605363/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com