【发布时间】:2016-03-03 10:48:11
【问题描述】:
我创建了以下图表:
我使用的javascript函数如下:
<script>
google.load('visualization', '1', {packages: ['corechart', 'bar', 'table']});
google.setOnLoadCallback(loadcharts);
var dept= 'General Ward';
function drawBasic() {
//alert(dept);
var abc = $.ajax({url:'kpi23.php? dept='+dept,async:false,dataType:"json",}).responseText;
var data = new google.visualization.DataTable(abc);
var formatter = new google.visualization.NumberFormat({
pattern: 'short'
});
formatter.format(data, 1);
formatter.format(data, 2);
formatter.format(data, 3);
formatter.format(data, 4);
formatter.format(data, 5);
formatter.format(data, 6);
var view = new google.visualization.DataView(data);
view.setColumns([0,
1, {calc: "stringify", sourceColumn: 1, type: "string", role: "annotation"},
2, {calc: "stringify", sourceColumn: 2, type: "string", role: "annotation"},
3, {calc: "stringify", sourceColumn: 3, type: "string", role: "annotation"},
4, {calc: "stringify", sourceColumn: 4, type: "string", role: "annotation"},
5, {calc: "stringify", sourceColumn: 5, type: "string", role: "annotation"},
6, {calc: "stringify", sourceColumn: 6, type: "string", role: "annotation"}
]);
var options = {
chart: {
title: 'Footfall by Day of Week'
},
annotations: {
textStyle: {
fontSize: 10
}
},
height: 400,
series: {
0:{color:'#083874'},
1:{color:'#94CAFC'},
2:{color:'#EBBA25'},
3:{color:'#F59E47'},
4:{color:'#9A9FA2'}
},
vAxis: {title: "Revenue", titleTextStyle: {italic: false}, gridlines: {color: 'transparent'}, viewWindowMode: "explicit", viewWindow: {min: 0}, format: 'short'},
hAxis: {title: "Month", titleTextStyle: {italic: false}, gridlines: {color: 'transparent'}},
legend: {position: 'top', maxLines: 3},
bar: {groupWidth: '70%'},
isStacked: true
};
var chart = new google.visualization.ColumnChart(
document.getElementById('chart_div'));
chart.draw(view, options);
}
我看到 X 轴上出现了一些零,而 JSON 不包含任何 0。我怎样才能摆脱这些零?
【问题讨论】:
-
它实际上在数据库中有一个NULL值!我该怎么办?
标签: javascript google-api google-visualization