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

258
Views
Cómo separar series de gráficos en diferentes paneles (Chart.js)

Estoy trabajando en el proyecto ASP.NET (.NET Framework 4.0) y uso Chart.js (versión 3.5.0) para crear gráficos a partir de datos. En este gráfico, el eje x es el mes del año y el eje y es para el valor de los datos. Debido a que hay 2 series con diferentes unidades de valor, quiero que la serie esté en un panel diferente, como se muestra en la imagen a continuación:

ingrese la descripción de la imagen aquí

En la imagen, ambas series comparten el mismo eje x pero se colocan en un panel diferente (cada panel también tiene un eje y diferente).

Por lo que he intentado, podría hacer que el gráfico tenga varios ejes Y en el lado diferente como este:

ingrese la descripción de la imagen aquí

Pero según el requisito, el gráfico no debe superponerse entre sí y ser como en la primera imagen, por lo que me pregunto si es posible separarlo en un panel diferente.

Aquí está mi código

 var chart; function DrawChart() { if (chart) chart.destroy(); var labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; var data = { datasets: [{ label: 'Volume (Cubic Metre)', data: [2900, 2105, 1950, 2030, 2105, 1950, 1040, 1600, 2300, 3000, 2020, 1700, 2100, 2000, 2800], pointRadius: 0, pointStyle: 'line', borderColor: '#F37B2D', backgroundColor: '#F37B2D', yAxisID: 'y1' }, { label: 'Price ($)', data: [350, 320, 380, 350, 315, 355, 190, 200, 240, 350, 270, 300, 250, 280, 320], pointRadius: 0, pointStyle: 'rect', borderColor: '#4473C5', backgroundColor: '#4473C5', fill: true, yAxisID: 'y' }, ], labels: labels, }; var config = { type: 'line', data: data, options: { maintainAspectRatio: false, scales: { x: { ticks: { minRotation: 90, maxRotation: 90 } }, y: { position: 'left', beginAtZero: true, title: { display: true, text: '$' } }, y1: { position: 'right', beginAtZero: true, title: { display: true, text: 'Cubic Metre' }, grid: { drawOnChartArea: false } } }, plugins: { legend: { position: 'bottom', reverse: true, labels: { usePointStyle: true, padding: 25, } } } } }; var ctx = document.getElementById('chart'); chart = new Chart(ctx, config); } $(function() { DrawChart(); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Conecté el eje y, usé 'apilar', apagué la posición a la izquierda y a la derecha

Código de ejemplo

 options: { maintainAspectRatio: false, scales: { x: { ticks: { minRotation: 90, maxRotation: 90 } }, y: { stack: 'chart', // add stack //position: 'left', beginAtZero: true, title: { display: true, text: '$' } }, y1: { stack: 'chart', // add stack offset: true, // add offset //position: 'right', beginAtZero: true, title: { display: true, text: 'Cubic Metre' }, grid: { drawOnChartArea: 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!