gpt4 book ai didi

javascript - google-visualization-errors : container is null. 消息:一位或多位参与者绘制失败()

转载 作者:行者123 更新时间:2023-11-30 00:05:33 26 4
gpt4 key购买 nike

我正尝试在我的网络应用程序中使用 Google 仪表板,但出现以下错误。

google-visualization-errors: container is null. message: One or more participants failed to draw()

我的代码类似于Google Documentation代码建议,但我仍然面临错误。

我的 JS(通过 C# 生成)-

<script type='text/javascript'>
google.charts.load('current', {
'packages': ['corechart', 'controls']});

google.charts.setOnLoadCallback(drawDashboard);

function drawDashboard() {

var data = google.visualization.arrayToDataTable([
['Status', 'Count'],
['Closed', 671],
['Resolved', 5],
['Test', 3]
]); //test///
var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));

var slider = new google.visualization.ControlWrapper({
'controlType': 'NumberRangeFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'Count'
}
});

var pieChart = new google.visualization.ChartWrapper({
'chartType': 'PieChart',
'containerId': 'divIncidentStatus',
'options': {
'width': 300,
'height': 300,
'pieSliceText': 'value',
'legend': 'right'
}
});

dashboard.bind(slider, pieChart);
dashboard.draw(data);

}
</script>

HTML

 <div class="panel panel-default">
<div class="panel-body">
<div class="dashboard_div">
<div class="filter_div"></div>
<div id="divIncidentStatus"></div>
</div>

</div>
</div>

P.S - 我曾尝试在我的 HTML DIV 之前和之后调用 JS 代码,但没有任何帮助。

最佳答案

好像打错了
需要设置 id 属性,而不是 class
dashboard_divfilter_div

而不是...

    <div class="dashboard_div">
<div class="filter_div"></div>
<div id="divIncidentStatus"></div>
</div>

改为...

    <div id="dashboard_div">
<div id="filter_div"></div>
<div id="divIncidentStatus"></div>
</div>

请参阅以下工作片段...

google.charts.load('current', {
'callback': function () {
var data = google.visualization.arrayToDataTable([
['Status', 'Count'],
['Closed', 671],
['Resolved', 5],
['Test', 3]
]);
var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));
var slider = new google.visualization.ControlWrapper({
'controlType': 'NumberRangeFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'Count'
}
});
var pieChart = new google.visualization.ChartWrapper({
'chartType': 'PieChart',
'containerId': 'divIncidentStatus',
'options': {
'width': 300,
'height': 300,
'pieSliceText': 'value',
'legend': 'right'
}
});
dashboard.bind(slider, pieChart);
dashboard.draw(data);
},
'packages': ['corechart', 'controls']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div class="panel panel-default">
<div class="panel-body">
<div id="dashboard_div">
<div id="filter_div"></div>
<div id="divIncidentStatus"></div>
</div>
</div>
</div>

关于javascript - google-visualization-errors : container is null. 消息:一位或多位参与者绘制失败(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38678008/

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