How to change Chart.js display c,

Asked

Viewed 1,615 times

1

I am learning to work chartsjs bring date, with value January with 10 clients, the scale is 0.5, 1.0,1.5,2.0 I would like to deichar with 1,2,3,4,... there is no half client

/*********************************** GRÁFICO DE LINHAS DIARIO ***********************************/
function os_dia() {
var periodoDia = $('#os_select').val();
$.ajax({
    type: 'POST',
    dataType: 'json',
    data: {
        periodoDia: periodoDia
    },
    url: BASE_URL + 'home/lista_homeDia',
    success: function(resposta) {
        console.log(resposta);
        data = {
            labels: Object.keys(resposta),
            datasets: [{
                label: 'OS por Dia',
                data: ret(resposta),
                borderWidth: 2,
                borderColor: '#80B6ED',
                backgroundColor: '#80B6ED',
                fill: false
            }]
        };
        options = {
            labels: {
                fontStyle: 'bold'
            }
        };
        Chart.defaults.global.responsive = true;
        var contexto = document.getElementById("graficoOsDia").getContext("2d");
        grafico = new Chart(contexto, {
            type: 'line',
            data: data,
            options: options
        });
    }
});
        }
     function ret(param) {
          var valores = [];
      $.each(param, function(key, val) {
    valores.push(val);
     });
     return valores;
      }



                os_dia();

             $("#os_select").change(function() {
           os_dia();
            });

1 answer

4


You can add one to the X-axis and Y-axis scale

scales: {
    yAxes: [{
        ticks: {
            max: 5,
            min: 0,
            stepSize: 1
        }
    }]
}

In the option max you choose the maximum scale value, in the min the minimum value, in stepSize is how much your scale will increase, in your case: 1.

EDIT: You don’t need to pass the amount min and max if you don’t want it, it’s just information.

You can find more information here http://www.chartjs.org/docs/latest/axes/cartesian/linear.html#step-size

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.