【问题标题】:How to display currency on Google charts line chart?如何在谷歌图表折线图上显示货币?
【发布时间】:2021-03-10 09:21:24
【问题描述】:

我正在尝试在 Google API 折线图中将货币显示为 Y 轴数据:

在 Y 轴上,我希望数字显示为 $0.00、$4.00、$8.00、$12.00、$16.00。

这是我用来填充图表的代码:

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);

    }

这适用于当鼠标悬停在图表上的某个点上时显示的工具提示,但它不会在图表的 Y 轴上显示为货币。

【问题讨论】:

    标签: javascript charts


    【解决方案1】:

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

    尝试像这样将vAxis: {format: 'currency'} 添加到您的options

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

    【讨论】:

      【解决方案2】:

      您是否尝试将vAxis.ticksConfiguration Options 添加到您的选项中?

      这样……

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-16
        • 1970-01-01
        • 2013-04-28
        • 2015-12-03
        相关资源
        最近更新 更多