我正在使用Google图表API创建柱形图。我创建了所有数据列并在列中显示了注释。但问题是,如果列值为零,则不显示注释。如何解决这个问题。我需要显示'0'。
我的代码是:
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawChart4);
function drawChart4() {
var data = new google.visualization.DataTable();
data.addColumn({ type: 'string', lable:'Something'});
data.addColumn('number','SLA Met');
data.addColumn({ type: 'number', role: 'annotation'});
data.addColumn('number','SLA Not Met');
data.addColumn({ type: 'number', role: 'annotation'});
data.addRows([
['Ancillary',<%=ANCILLARY_MET %>,<%=ANCILLARY_MET %>,<%=ANCILLARY_NOTMET%>,<%=ANCILLARY_NOTMET%> ],
['CIS',<%=CIS_MET %>,<%=CIS_MET %>,<%=CIS_NOTMET%>,<%=CIS_NOTMET%>],
['ERP FSCM',<%=FSCM_MET %>,<%=FSCM_MET %>,<%=FSCM_NOTMET%>,<%=FSCM_NOTMET%>],
['ERP HCM',<%=HCM_MET %>,<%=HCM_MET %>,<%=HCM_NOTMET%>,<%=HCM_NOTMET%>]
]);
var options = {'colors' : ['#3366CC', '#fcb441'],
title: 'Resolution SLA(Tower Wise)',titleTextStyle:{fontName:'"Arial"'},
hAxis: {title: 'Tower', titleTextStyle: {color: 'black',fontSize:'15',fontName:'"Arial"'}},
vAxis: {minValue:0},
legend:{position: 'bottom'},
tooltip:{trigger:'none'}
};
var chart = new google.visualization.ColumnChart(document.getElementById('g5'));
chart.draw(data, options);
}
答案 0 :(得分:3)
您似乎使用错误的类型number
进行注释。对于
{ type: 'string', role: 'annotation'}
并输入为字符串,即使是值&#39; 0&#39;也显示注释。
更新:为了澄清,您只需要更改注释的输入类型,例如
['Ancillary', 15, 15, 3, 3 ],
到
['Ancillary', 15, '15', 3, '3' ]
所以你的代码是:
data.addColumn({ type: 'string', lable:'Something'});
data.addColumn('number','SLA Met');
data.addColumn({ type: 'string', role: 'annotation'});
data.addColumn('number','SLA Not Met');
data.addColumn({ type: 'string', role: 'annotation'});