javascript - Google Chart 不是 div 宽度的 100% - 包含从代理表重绘图表的事件监听器

标签 javascript charts google-visualization

我已经实现了这篇文章中@WhiteHat的建议Google Chart not taking up 100% of space

我的<div>宽度为 100%,但我的图表仍然仅呈现 400 像素宽。参见图片。 enter image description here

我设置了以下图表选项。

        "chartType": "ComboChart",
        "containerId": "chartnull_G3G",   
        "view": {"columns":[2,3]}, 
        "options": {
           "chartArea": { "left": "auto", "right": "auto", "top": 50, "bottom": "auto", "width": "80%", "height": "60%", "backgroundColor": "white" },
           "width": "100%",
           "height": 500    
         }

我的程序流程包含以下步骤。

//proxyTable_default and comboChart_default simply creates the content for the chart - this works without problem

var proxyTable = new google.visualization.ChartWrapper(proxyTable_default(element_suffix));
var chart = new google.visualization.ChartWrapper(comboChart_default(null, element_suffix, json.comboChart.options));

addListenersComboChart();

window.addEventListener('resize', function () { proxyTable.draw(); }, false);

proxyTable.setDataTable(proxyView)
proxyTable.draw();

这是上面引用的我的监听器和重绘函数。

function addListenersComboChart() {
    google.visualization.events.addListener(proxyTable, 'ready', function () {
        redrawComboChart(element_suffix, json.comboChart);
    });
}

function redrawComboChart(element_suffix, comboChart) {
    //Do many steps to calculate the finalView_forChart - this works without problem
    chart.setDataTable(finalView_forChart);
    chart.draw();
}

我无法发布完整的代码库,因为它有 1000 多行长。一切正常,直到图表未绘制 100% 宽。我错过了什么?

一如既往,我很感谢您的反馈。

最佳答案

@Whitehat 是正确的。 div 一直隐藏,直到调用 .draw() 为止。 lib_loadingStatus() 取消隐藏 div

之前

proxyTable.setDataTable(proxyView);
proxyTable.draw();    
lib_loadingStatus(element_suffix, "done"); //This code unhides the chart <div>

之后

proxyTable.setDataTable(proxyView);    
lib_loadingStatus(element_suffix, "done"); //This code unhides the chart <div>    
proxyTable.draw();
  

图表现在绘制完整尺寸。非常感谢@WhiteHat(再次拯救了这一天!)

关于javascript - Google Chart 不是 div 宽度的 100% - 包含从代理表重绘图表的事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67589324/

相关文章:

javascript - php 不是 "echo-ing"javascript 正确

javascript - 如何将数据发送到 PHP 脚本并使用 jQuery AJAX load() 指令

javascript - Flot.js 实时绘图上的单个点不可见

javascript - 应用于 .ChartWrapper() 元素时出现 Google Visualization .getSelection() 错误

javascript - 错误 : You called the draw() method with the wrong type of data rather than a DataTable or DataView

javascript - Google Charts (AreaChart) 如何检测缩放变化

java - 如何在线编译Java代码?

javascript - 需要让我的网站和码笔版一样

javascript - 如何在容器大小动态变化时调整 canvasjs 图表的大小?

javascript - 当我在饼图中选择一个切片时,我想显示切片选择的某种视觉表示