简体   繁体   English

如何在 Google 图表折线图上显示货币?

[英]How to display currency on Google charts line chart?

I am trying to display currency as the Y axis data in a Google API line chart:我正在尝试将货币显示为 Google API 折线图中的 Y 轴数据:

谷歌折线图示例

In the Y axis, I want the numbers to be shown as $0.00, $4.00, $8.00, $12.00, $16.00.在 Y 轴上,我希望数字显示为 $0.00、$4.00、$8.00、$12.00、$16.00。

Here is the code I'm using to populate the chart:这是我用来填充图表的代码:

function drawDailySales() {

        var data = google.visualization.arrayToDataTable([

            ['Date', 'Daily Sales'],

            <?php foreach ($daily_sales as $date => $sales) {

                echo "['".$date."', {v: ".$sales['Amount'].", f: '$".number_format($sales['Amount'], 2, '.', ',')."'}],";   

            } ?>

            ]);

            var options = {
                title: 'Daily Sales',
                legend: { 
                    position: 'bottom' 
                }

            };

        var chart = new google.visualization.LineChart(document.getElementById('daily_sales'));

        chart.draw(data, options);

    }

This works on the tooltip that displays when the mouse is hovered over a point on the chart, but it doesn't display as currency in the Y axis on the chart.这适用于当鼠标悬停在图表上的某个点上时显示的工具提示,但它不会在图表的 Y 轴上显示为货币。

11/2020 Update (another solution) 11/2020 更新(另一种解决方案)

Try adding vAxis: {format: 'currency'} to your options like this:尝试将vAxis: {format: 'currency'}到您的options如下所示:

var options = {
  vAxis: {format: 'currency'}
};

Have you tried adding vAxis.ticks to your options, from the Configuration Options ?您是否尝试从Configuration Options vAxis.ticks添加到您的选项中

As such...像这样...

vAxis: { ticks: [{v:0, f:'$0.00'}, {v:4, f:'$4.00'}, ...] }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM