Jquery graphics that have thousands of formations on the x and y axes

1

I would like to know if anyone knows of any plugin or library to make graphics that place the numerical values in thousands formats.

I would really appreciate your help

    
asked by Danilo 23.05.2017 в 07:32
source

1 answer

2

Check out "Tick Configuration (callback)" from chart.js .

Allows you complete freedom to implement functions that convert raw data to the text you want.

I'll give you an example:

var contexto = document.getElementById('grafica').getContext('2d');
var grafica = new Chart(contexto, {
  type: 'line',
  data: {
    labels: ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo'],
    datasets: [{
      label: 'manzanas',
      data: [1200, 1900, 300, 1700, 600, 300, 700],
      backgroundColor: "rgba(153,255,51,0.4)"
    }, {
      label: 'naranjas',
      data: [200, 2900, 500, 500, 200, 300, 1000],
      backgroundColor: "rgba(255,153,0,0.4)"
    }]
  },
  options: {
    scales: {
      yAxes: [
        {
          ticks: {
            callback: function(valor, index, valores) {
              return Number(valor).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
            }
          },
          scaleLabel: {
            display: true,
            labelString: 'Cantidad'
          }
        }
      ],
      xAxes: [
        {
          scaleLabel: {
            display: true,
            labelString: 'Días de la semana'
          }
        }
      ]
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="grafica"></canvas>
    
answered by 23.05.2017 / 09:16
source