gpt4 book ai didi

google-visualization - 缩放谷歌可视化图表的选定区域

转载 作者:行者123 更新时间:2023-12-03 22:07:31 26 4
gpt4 key购买 nike

我正在研究 Google 可视化图表。我希望当我选择图表的特定区域时,我可以缩放该特定的选定区域。我也希望它对折线图、条形图、饼图做同样的事情

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', 'Company1');
data.addColumn('number', 'Company2');
data.addColumn('number', 'Company3');
data.addColumn('number', 'Company4');
data.addColumn('number', 'Company5');
data.addColumn('number', 'Company6');
data.addRows([
['Feb 1, 2012 - Feb 28, 2012', 10, 10, 5, 15, 10, 55]
]);
data.addRows([
['Mar 1, 2012 - Mar 31, 2012', 10, 10, 5, 15, 10, 55]
]);
var options = {
title: 'Total Reviews',
hAxis: {title: '', titleTextStyle: {color: 'blue'}}
};
var chart = new google.visualization.ColumnChart(document.getElementById('total'));
chart.draw(data, options);
google.visualization.events.addListener(chart, 'select', function() {
var selection = chart.getSelection()[0];
var label = data.getColumnLabel(selection.column);
// alert(label); //SOMETHING GOES HERE TO MAKE IT ZOOOM
})
}
</script>
</head>
<body>
<div id="total" style="width: 600px; height: 400px;"></div>
</body>
</html>

最佳答案

据我所知,通过配置选项,您应该能够使用名为 explorer 的选项

// before you pass the options to the drawing function
options.explorer = {
actions: ['dragToZoom', 'rightClickToReset']
/* you can add more options */
}

请查看 the line chart API 中的 explorer 和其他选项并阅读笔记

Note: The explorer only works with continuous axes (such as numbers or dates).

因此您的示例域列数据必须转换为实际的 Date 对象,并且您的第一列应定义为

data.addColumn('date','Date');

或者我喜欢的方式

data.addColumn({role:'domain', type:'date', label:'Date'});

关于google-visualization - 缩放谷歌可视化图表的选定区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18508908/

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