我有一个柱形图并且工作正常,但我想总是显示正数,但我强制负数来“分割”顶部和底部的条形。
他是一个例子:
这是我的代码
google.load('visualization','1.1',{packages:['corechart']});
google.setOnLoadCallback(function(){
var GoogleChart=new google.visualization.ColumnChart(document.getElementById( 'chart' ));
var data = google.visualization.arrayToDataTable([
["Age","Male","Female"],
["<15",{"v":0,"f":"0%"},{"v":0,"f":"0%"}],
["15-20",{"v":8.3333333333333,"f":"8,3333333333333%"},{"v":0,"f":"0%"}],
["20-25",{"v":75,"f":"75%"},{"v":-8.3333333333333,"f":"8,3333333333333%"}],
["25-30",{"v":0,"f":"0%"},{"v":0,"f":"0%"}],
["30-35",{"v":0,"f":"0%"},{"v":0,"f":"0%"}],
["35-40",{"v":0,"f":"0%"},{"v":0,"f":"0%"}],
["40-45",{"v":8.3333333333333,"f":"8,3333333333333%"},{"v":0,"f":"0%"}],
["45-50",{"v":0,"f":"0%"},{"v":0,"f":"0%"}],
["50-55",{"v":0,"f":"0%"},{"v":0,"f":"0%"}],
["55-60",{"v":0,"f":"0%"},{"v":0,"f":"0%"}],
[">60",{"v":0,"f":"0%"},{"v":0,"f":"0%"}]
]);
new google.visualization.NumberFormat({"pattern":"#,##%"}).format(data, 1);
new google.visualization.NumberFormat({"pattern":"#,##%"}).format(data, 2);
var options ={
"isStacked":true,
"hAxis":{
"title":"age"
},
"vAxis":{
"title":"Percentage",
"format":"#,##%",
"viewWindowMode":"explicit",
"viewWindow":{
"min":-100,
"max":100
}
}
};
GoogleChart.draw(data, options);
我不知道如何删除否定符号(“ - ”)。 感谢
P.S:Google Charts 1.1
答案 0 :(得分:1)
Google可视化模式格式是ICU pattern set的子集。通过这种方式,您可以为正数和负数指定子模式以避免减号(因为如果未指定负子模式,则默认情况下将获得减去前缀):
format: "#,##%;#,##%"
不幸的是,这在可视化中无效 - 它抱怨“太多百分比/ permills ” - 但由于%
只是“乘以100并显示为百分比“ - 然后您只需添加,00%
作为字符串后缀:
vAxis:{
format:"#,##',00%';#,##',00%'",
...
}
new google.visualization.NumberFormat({"pattern":"#,##',00%';#,##',00%'"}).format(data, 1);
new google.visualization.NumberFormat({"pattern":"#,##',00%';#,##',00%'"}).format(data, 2);
现在从vAxis和工具提示中删除了减号。
演示 - &gt;的 http://jsfiddle.net/pcvtf7q9/ 强>