我有一个Google注释图表,显示0到1之间的值,如下所示:jsfiddle
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Kepler-22b mission');
data.addColumn('string', 'Kepler title');
data.addColumn('string', 'Kepler text');
data.addColumn('number', 'Gliese 163 mission');
data.addColumn('string', 'Gliese title');
data.addColumn('string', 'Gliese text');
data.addRows([
[new Date(2314, 2, 15), 0.12400, undefined, undefined,
0.10645, undefined, undefined],
[new Date(2314, 2, 16), 0.24045, 'Lalibertines', 'First encounter',
0.12374, undefined, undefined],
[new Date(2314, 2, 17), 0.35022, 'Lalibertines', 'They are very tall',
0.15766, 'Gallantors', 'First Encounter'],
[new Date(2314, 2, 18), 0.12284, 'Lalibertines', 'Attack on our crew!',
0.34334, 'Gallantors', 'Statement of shared principles'],
[new Date(2314, 2, 19), 0.8476, 'Lalibertines', 'Heavy casualties',
0.66467, 'Gallantors', 'Mysteries revealed'],
[new Date(2314, 2, 20), 0, 'Lalibertines', 'All crew lost',
0.79463, 'Gallantors', 'Omniscience achieved']
]);
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
var options = {
displayAnnotations: true,
scaleFormat: '#'
};
chart.draw(data, options);
}
默认情况下,垂直轴的格式为整数,这对于读取图表并不理想。 documentation有一个scaleFormat选项(默认'#'表示整数)但不提供任何替代选项。我无法在文档中获得任何其他数字格式选项。
如何将Y轴刻度格式化为1位小数?
答案 0 :(得分:1)
#
只是一个例子,您可以按照您想要的任何方式格式化。对于带有1位小数的数字,您需要执行以下操作:
scaleFormat: '#.#'