如何使用ChartWrapper和格式化程序在线/条形图上的工具提示中添加后缀?这是ChartWrapper的代码
function drawChartb() {
var wrapper = new google.visualization.ChartWrapper({
chartType: 'LineChart',
dataTable: [['Person', 'Score'], [1, .50], [2, .25]],
options: {'legend': 'bottom', 'colors': ['#D70005'], 'chartArea': {left: 40, top: 10, width: 450}, 'vAxis': {format: '#,###%', 'viewWindow': {max: 1.05, min: .2}}, 'pointSize': 6},
containerId: 'chart_div'
});
wrapper.draw();
}
这就是我在不使用chartwrapper的情况下完成的 .
// set tooltip as percentage
var formatter = new google.visualization.NumberFormat({
pattern: '#%',
fractionDigits: 2
});
formatter.format(data, 1);
谢谢
2 回答
您可以在包装器外定义数据,在其上使用formatter,然后将dataTable设置为等于该数据源:
结果:
对于那些使用Google JSON schema生成图表数据且无法使用ChartWrapper使用NumberFormat的人,可以直接将格式应用于行"f":null
注意:
Using DataTable > OK
Using ChartWrapper > BAD
这就是我使用Google JSON正确格式化数据的方式 .
示例JSON:
这是生成该JSON的PHP代码
饼图将显示$ nutsTotalFormat的格式化结果
“$ 945.59”