如何定制“没有足够的列来绘制所请求的图表”信息? [英] How to customize "not enough columns given to draw the requested chart" message?
问题描述
有任何方法自订Google图表,以免他们显示这个「红色」讯息吗?
Is there any way to customize Google charts to prevent them from displaying this 'red' message? E.g., silently drawing nothing instead?
推荐答案
google图表/可视化提供的一系列事件,方法和工具用于自定义错误处理,错误消息等。
There is a bunch of events, methods and tools google charts / visualization offers for customizing error handling, error messages and so on.
例如,请参阅 https:// developers .google.com / chart / interactive / docs / reference#errordisplay 或 https:// developers .google.com / chart / interactive / docs / examples#querywrapper
根据您的要求,最简单的方法是简单附加errorhandler,并在该处理程序中,通过 google.visualization.errors
删除错误。
According to what you are asking for, the easiest way would be to simply attach an errorhandler and in that handler, remove the error through 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);
}
viola!尝试将 errorHandler
和 google.visualization.events.addListener(chart,'error',errorHandler);
添加到您的现有代码,并看到差异(这是所有你需要的)。
viola! Try add the errorHandler
and google.visualization.events.addListener(chart, 'error', errorHandler);
to your existing code, and see the difference (this is all you need).
这篇关于如何定制“没有足够的列来绘制所请求的图表”信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!