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

124
Views
Frontend y backend para gráficos usando chartjs, mongodb y controlador

Soy nuevo en generar un gráfico usando el mecanismo ajax y chartjs. Parece que logré generar el gráfico pero están trazados incorrectamente. Por favor, ilumíneme sobre cómo podría mejorar. Realmente lo agradecería Gracias

El siguiente es mi código en javascript para trazar el gráfico

 var ctx = document.getElementById('myChart').getContext('2d'); $.ajax({ url:"/dashboard", type:"POST", data: {}, error: function() { alert("Error"); }, success: function(data, status, xhr) { debugger // declare all variables to draw chart var chartDim = {}; var chartDim = data.chartDim; var xLabels = data.labels; var vLabels = []; var vData = []; let newValues =[] // get from database to push to draw the chart for (const [key, values] of Object.entries(chartDim)) { vLabels.push(key); let newValues = values.map(myFunction); debugger; vData.push(newValues); } debugger var myChart = new Chart(ctx, { data: { labels: xLabels, datasets: [] }, options: { responsive: false } }); // draw to chart debugger for (i= 0; i < vLabels.length; i++ ) { myChart.data.datasets.push({ label: vLabels[i], type: "bar", // borderColor: '#'+(0x1ff0000+Math.random()*0xffffff).toString(16).substr(1,6), borderColor: '#'+(0x1100000+Math.random()*0xffffff).toString(16).substr(1,6), backgroundColor: "rgba(249, 238, 236, 0.74)", data: vData[i], spanGaps: true }); myChart.update(); } }})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto sucede porque mientras crea su gráfico, empuja cada punto de datos como un nuevo conjunto de datos. En su lugar, solo necesita usar un solo conjunto de datos y pasarle la matriz de datos de esta manera:

 var myChart = new Chart(ctx, { type: 'bar', data: { labels: xLabels, datasets: [{ borderColor: '#' + (0x1100000 + Math.random() * 0xffffff).toString(16).substr(1, 6), backgroundColor: "rgba(249, 238, 236, 0.74)", data: vData, spanGaps: true }] }, options: { responsive: false } });
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!