答案 0 :(得分:9)
要删除Google错误,请在图表或其他对象上收听'error'
事件
触发事件时,请使用google.visualization.errors.removeError
在此,我故意导致错误,将其从Google chart
中移除,并将其显示在我自己的div
google.load('visualization', '1', {packages:['corechart'], callback: drawChart});
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Element", "Density", { role: "style" } ]
]);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1,
{ calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation" },
2]);
var chart = new google.visualization.ColumnChart(document.getElementById("chart_div"));
google.visualization.events.addListener(chart, 'error', function (googleError) {
google.visualization.errors.removeError(googleError.id);
document.getElementById("error_msg").innerHTML = "Message removed = '" + googleError.message + "'";
});
chart.draw(view, {height: 20});
}

<script src="https://www.google.com/jsapi"></script>
<div id="chart_div"></div>
<div id="error_msg"></div>
&#13;