gpt4 book ai didi

google-visualization - 如何在 Google Charts 中指定小数点分隔符?

转载 作者:行者123 更新时间:2023-12-04 14:11:13 24 4
gpt4 key购买 nike

有没有办法在 Google Charts 中指定小数点分隔符?

默认情况下,它似乎基于语言环境,但是我需要将小数点分隔符设为“点”而不是某些语言环境的逗号(我的用户所在的语言环境中逗号作为小数点分隔符是默认设置) ,但被认为是过时的/过时的)

这将适用于所有数字,从轴标签到工具提示。其余的语言环境选项将保持不变。

最佳答案

Google Visualization API 提供 formatters可用于重新格式化可视化中的数据

根据 NumberFormat :

Describes how numeric columns should be formatted. Formatting options include specifying a prefix symbol (such as a dollar sign) or the punctuation to use as a thousands marker.



下面的示例演示了如何将格式化程序应用于 Salary列以使用 . 呈现其值符号( decimalSymbolgroupingSymbol NumberFormat 对象的属性用于此目的)

google.load("visualization", "1", { packages: ["table"] });
google.setOnLoadCallback(drawChart);

function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time');
data.addRows(5);
data.setCell(0, 0, 'John');
data.setCell(0, 1, 10000);
data.setCell(0, 2, true);
data.setCell(1, 0, 'Mary');
data.setCell(1, 1, 25000);
data.setCell(1, 2, true);
data.setCell(2, 0, 'Steve');
data.setCell(2, 1, 8000);
data.setCell(2, 2, false);
data.setCell(3, 0, 'Ellen');
data.setCell(3, 1, 20000);
data.setCell(3, 2, true);
data.setCell(4, 0, 'Mike');
data.setCell(4, 1, 12000);
data.setCell(4, 2, false);

var formatter = new google.visualization.NumberFormat({ prefix: '$',decimalSymbol: '.', groupingSymbol: '.' });
formatter.format(data, 1); // Apply formatter to second column

var view = new google.visualization.DataView(data);
view.setColumns([0, 1]);


var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(view, { width: '420px', height: '240px' });
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="table_div"></div>


更新

根据 Customizing Axes您可以使用 hAxis.format 控制标签编号的格式。和 vAxis.format
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);

function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time');
data.addRows(5);
data.setCell(0, 0, 'John');
data.setCell(0, 1, 0.1000);
data.setCell(0, 2, true);
data.setCell(1, 0, 'Mary');
data.setCell(1, 1, 0.2500);
data.setCell(1, 2, true);
data.setCell(2, 0, 'Steve');
data.setCell(2, 1, 0.800);
data.setCell(2, 2, false);
data.setCell(3, 0, 'Ellen');
data.setCell(3, 1, 0.2000);
data.setCell(3, 2, true);
data.setCell(4, 0, 'Mike');
data.setCell(4, 1, 0.1200);
data.setCell(4, 2, false);

var formatter = new google.visualization.NumberFormat({ prefix: '$', decimalSymbol: '.', groupingSymbol: '.' });
formatter.format(data, 1); // Apply formatter to second column

var view = new google.visualization.DataView(data);
view.setColumns([0, 1]);


var table = new google.visualization.LineChart(document.getElementById('table_div'));
table.draw(view, { width: '420px', height: '240px', vAxis: { format:'$#,##0.00' } });
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="table_div"></div>

关于google-visualization - 如何在 Google Charts 中指定小数点分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32135119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com