0

是否可以删除垂直轴上的十进制数字?我正在尝试显示两个图表,但我不知道如何删除这些十进制数字,因为选项刻度在材料图表中不起作用。

显示图表的脚本代码:

<script type="text/javascript">

            // Load the Visualization API and the line package.

google.charts.load('current', {'packages':['bar']});//  google.charts.load('visualization', '1', {'packages':['corechart']}); 


            // Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

function drawChart() {

   var data = google.visualization.arrayToDataTable([
    ['Rok', 'Pocet'],

    <?php
    foreach ($chart_data as $data) {
          echo "['".$data["rok"]."', ".$data["pocet"]."],";

   }
     ?>



    ]);

    var data2 = google.visualization.arrayToDataTable([
    ['Rok', 'Pocet'],

    <?php
    foreach ($customers_data as $data) {
          echo "['".$data["rok"]."', ".$data["pocet"]."],";

   }
     ?>



    ]);     

    var options = {
                  chart: {
                        title: 'Chart 1',

                   },


                };

    var options2 = {chart: {
                        title: 'Chart 2',

                   },

                };



    var chart = new google.charts.Bar(document.getElementById('columnchart_material')); 

    chart.draw(data,google.charts.Bar.convertOptions(options));

    var chart2 = new google.charts.Bar(document.getElementById('columnchart_material2'));    

    chart2.draw(data2,google.charts.Bar.convertOptions(options2));

            }

</script>

现在显示如下:当前状态

我只想显示 0, 1, 2 ...

感谢您的所有建议。

4

1 回答 1

2

它有一个设置,您可以添加到您的选项 var。例如,如果要添加两位浮点数:

vAxis: {format:'0.00'}
hAxis: {format:'0.00'}

您可以在格式属性中添加尽可能多的浮点数,例如:

vAxis: {format:'0.00000'}
vAxis: {format:'0.000'}

如果你想删除小数:

vAxis: {format:'0'}
vAxis: {format:'0'}

{format: ''}: displays numbers with no formatting (e.g., 8000000)
{format: 'decimal'}: displays numbers with thousands separators (e.g., 8,000,000)
{format: 'scientific'}: displays numbers in scientific notation (e.g., 8e6)
{format: 'currency'}: displays numbers in the local currency (e.g., $8,000,000.00)
{format: 'percent'}: displays numbers as percentages (e.g., 800,000,000%)
{format: 'short'}: displays abbreviated numbers (e.g., 8M)
{format: 'long'}: displays numbers as full words (e.g., 8 million)

var options2 = {
    chart: {
        title: 'Chart 2',
    },
    {
        hAxis: {
            format: '0'
        }
    },
    {
        hAxis: {
            format: '0'
        }
    }

};

演示

数字格式文档

于 2019-05-04T12:14:54.063 回答