如何删除Google物料图表中的小数点

时间:2019-05-04 11:43:48

标签: javascript php charts google-visualization column-chart

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

显示图表的脚本代码:

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

现在显示如下:Current state

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

感谢您的所有建议。

1 个答案:

答案 0 :(得分:0)

它具有可以添加到选项var中的设置。例如,如果要添加两位数字float:

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

您可以在格式属性中添加任意数量的浮点数字,例如:

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

如果要删除小数点:

vAxis: {format:'none'}
vAxis: {format:'none'}

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

{format: 'none'}: 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'
        }
    }

};

Demo