重绘谷歌图表

时间:2012-02-20 00:16:59

标签: google-visualization

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

1 个答案:

答案 0 :(得分:4)

您可以随时再次调用图表对象上的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);
}