简体   繁体   中英

How to remove decimal values in google material charts

Is it possible to remove decimal numbers in vertical axis? I'm trying to display two charts but I don't know how to remove these decimal numbers because option ticks is not working in material charts.

Code of script which is displaying charts:

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

It's now displaying like this: Current state

And I want to just display 0, 1, 2...

Thank you for all suggestions.

It has a setting you can add to your options var. For instance, if you want to add two digits float:

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

You can add as much as float digits you wish to, in the format attributes, such as:

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

And if you wish to remove the decimals:

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

};

Demo

Number Formats Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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