【发布时间】:2014-06-11 06:48:22
【问题描述】:
这是我的谷歌图表脚本。如果没有数据,我会尝试显示一个空图表并隐藏消息“没有足够的列来绘制请求的图表”。你知道我的代码有什么问题吗?只要没有数据,该错误消息仍然会出现。我参考了How to customize "not enough columns given to draw the requested chart" message?,但它不适用于我的情况。谢谢。
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChartCampaign);
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 drawChartCampaign() {
var data = google.visualization.arrayToDataTable(<?= generateChartOverview($row['campaignId'], $start_date, $end_date, false, true, $ad); ?>);
var options = {
title: '',
pointSize: 3,
animation: { duration: 1000, easing: 'out' },
hAxis: {title: 'Date', titleTextStyle: {color: '#999999'}<?php if($boolInterval){ echo " , showTextEvery : $showTextEvery"; } ?>},
vAxis: {title: 'Clicks / Views', titleTextStyle: {color: '#999999'}, viewWindowMode:'explicit', viewWindow:{ min:0 }}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div_adsdetails'));
//attach the error handler here, before draw()
google.visualization.events.addListener(chart, 'error', errorHandler);
chart.draw(data, options);
}
</script>
【问题讨论】:
-
你知道在那种情况下你从
<?= generateChartOverview($row['campaignId'], $start_date, $end_date, false, true, $ad); ?>得到什么吗? -
是的,如果有数据,它会显示图表并且工作正常。但是当还没有数据时,图表会显示该错误消息。
-
我明白了,但是
<?= generateChartOverview($row['campaignId'], $start_date, $end_date, false, true, $ad); ?>的结果是什么?一个空字符串,一个空数组,一个空数组的数组还是一些垃圾?arrayToDataTable()的参数是什么?
标签: javascript charts google-visualization