有什么方法可以自定义 Google 图表以防止它们显示此“红色”消息吗?例如,默默地什么都不画?
最佳答案
Google 图表/可视化提供了大量事件、方法和工具,用于自定义错误处理、错误消息等。
例如,参见 https://developers.google.com/chart/interactive/docs/reference#errordisplay或 https://developers.google.com/chart/interactive/docs/examples#querywrapper
根据您的要求,最简单的方法是简单地附加一个错误处理程序,并在该处理程序中通过 google.visualization.errors
删除错误。
像这样:
function errorHandler(errorMessage) {
//curisosity, check out the error in the console
console.log(errorMessage);
//simply remove the error, the user never see it
google.visualization.errors.removeError(errorMessage.id);
}
function drawChart(json) {
var data = new google.visualization.DataTable(json); //here, JSON is buggy
var options = {
title: 'test'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
//attach the error handler here, before draw()
google.visualization.events.addListener(chart, 'error', errorHandler);
chart.draw(data, options);
}
中提琴!尝试将 errorHandler
和 google.visualization.events.addListener(chart, 'error', errorHandler);
添加到您现有的代码中,然后查看区别(这就是您的全部需要)。
关于javascript - 如何自定义 "not enough columns given to draw the requested chart"消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17559675/