Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
cambie la escala del eje para que sean números redondos en lugar de decimales - chart.js

Estoy trabajando con chart.js y parece que no puedo cambiar la escala del eje Y para mostrar números enteros, en este ejemplo me gustaría tener solo números redondos en la escala (1,2,3 ,4,5) en lugar del decimal (0 -0,5 - 1,0 - 1,5 - 2,0 - etc)

ingrese la descripción de la imagen aquí

Estoy usando un gráfico de barras vertical desde aquí: https://www.chartjs.org/docs/latest/samples/bar/vertical.html

y mi configuración actual es esta:

 var setVirtualBarChart = function (element, viewModel) { var chArea = element.getContext("2d"); var chartConfig = { type: 'bar', data: { labels: ['Categories'], datasets: [ { minBarLength: 2, label: '0-7 days', barPercentage: 0.75, categoryPercentage: 0.75, data: viewModel.ZeroToSevenDaysUser(), backgroundColor: window.chartColors.BrightVisibleGreen }, { minBarLength: 2, label: '8-30 days', barPercentage: 0.75, categoryPercentage: 0.75, data: viewModel.SevenToThirtyDaysUser(), backgroundColor: window.chartColors.Orange }, { minBarLength: 2, label: '30+ test days', barPercentage: 0.75, categoryPercentage: 0.75, data: viewModel.ThirtyPlusDaysUser(), backgroundColor: window.chartColors.BrightRed } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { xAxes: [ { stacked: false, display: true, scaleLabel: { display: true, //labelString: 'Categories', gridLines: { offsetGridLines: true } } } ], yAxes: [ { stacked: false, display: true, scaleLabel: { display: true, labelString: 'Number of invoices' }, ticks: { precision: 0, min: 0 } } ] } } }; VirtualBarChart = new Chart(chArea, chartConfig); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Está utilizando la sintaxis v2 mientras usa v3, en v3 todas las escalas son objetos y ya no son matrices. Para todos los cambios, lea la guía de migración

Ejemplo:

 const options = { type: 'bar', data: { labels: ["Red", "Blue", "Yellow"], datasets: [{ label: '# of Votes', data: [1, 2.5, 1.5], backgroundColor: ["Red", "Blue", "Yellow"] }] }, options: { scales: { y: { ticks: { stepSize: 1 }, } } } } const ctx = document.getElementById('chartJSContainer').getContext('2d'); new Chart(ctx, options);
 <body> <canvas id="chartJSContainer" width="600" height="400"></canvas> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.js"></script> </body>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!