重绘谷歌图表

发布于 2025-01-06 23:12:52 字数 124 浏览 5 评论 0原文

我有一个在可调整大小的元素内使用 google 可视化 API 呈现的表格图表。我需要在调整父元素大小后重新绘制表格。调整父元素的大小后,我可以单击列标题来重新排列表格,它还会重新绘制表格以适应新的大小,但我如何以编程方式执行此操作?

I have a table chart rendered with the the google visualization API inside a resizable element. I need to redraw the table after the parent element is resized. After I resize the parent element, I can click a column header to resort the table and it will also redraw the table to fit the new size, but how can i do this programatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬心 2025-01-13 23:12:52

您始终可以在图表对象上再次调用 draw() 函数。

// Global variables, as they are accessed by different functions.
var data;
var options;
var chart;

function drawVisualization() {
    // Create and populate the data table.
    data = new google.visualization.DataTable();
    data.addColumn('string', 'Column');
    data.addColumn('number', 'Value');
    data.addRows([['A', 27.49], ['B', 27.81]]);

    options = {width: 600, height: 600};
    chart = new google.visualization.ColumnChart(document.getElementById('visualization'));
    // Here we draw the visualization by first time
    chart.draw(data, options);
}

function resize() {
    options = {width: 300, height: 300};
    // Here we re-draw
    chart.draw(data, options);
}        

You can always call again the draw() function on your chart object.

// Global variables, as they are accessed by different functions.
var data;
var options;
var chart;

function drawVisualization() {
    // Create and populate the data table.
    data = new google.visualization.DataTable();
    data.addColumn('string', 'Column');
    data.addColumn('number', 'Value');
    data.addRows([['A', 27.49], ['B', 27.81]]);

    options = {width: 600, height: 600};
    chart = new google.visualization.ColumnChart(document.getElementById('visualization'));
    // Here we draw the visualization by first time
    chart.draw(data, options);
}

function resize() {
    options = {width: 300, height: 300};
    // Here we re-draw
    chart.draw(data, options);
}        
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文