如何自定义"没有足够的列来绘制所请求的图表"消息?

Mar*_*zzi 8 javascript google-visualization css3

有没有办法自定义Google图表以防止他们显示此"红色"消息?例如,默默地画什么?

dav*_*rad 9

谷歌图表/可视化提供了一系列事件,方法和工具,用于自定义错误处理,错误消息等.

例如,请参阅https://developers.google.com/chart/interactive/docs/reference#errordisplayhttps://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);
}
Run Code Online (Sandbox Code Playgroud)

中提琴!尝试将errorHandlerand 添加google.visualization.events.addListener(chart, 'error', errorHandler);到现有代码中,并查看差异(这就是您所需要的).