Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

388
Vistas
How to align multiple x axes in chart.js?

I have to create three line charts that share the same x-axis but are vertically stacked on top of each other with different y-axes.

Here is my current visualization.
enter image description here

Unfortunately, the x-axis tick marks do not line up because of the y-axis labels. How should I go about fixing this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just stack the axes:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange", "Black"],
    datasets: [{
        label: 'Dataset 1',
        data: [10, 30, 50, 20, 25, 44, -10],
        borderColor: 'red',
        backgroundColor: 'red'
      },
      {
        label: 'Dataset 2',
        data: [10000, 30000, 50000, 20000, 25000, 44000, -10000],
        borderColor: 'blue',
        backgroundColor: 'blue',
        yAxisID: 'y2',
      }
    ]
  },
  options: {
    scales: {
      y: {
        type: 'linear',
        position: 'left',
        stack: 'demo',
        grid: {
          borderColor: 'red'
        },
        title: {
          display: true,
          text: 'hello'
        }
      },
      y2: {
        offset: true,
        position: 'left',
        stack: 'demo',
        grid: {
          borderColor: 'blue'
        },
        title: {
          display: true,
          text: 'hello2'
        }
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdn.jsdelivr.net/npm/chart.js@3.6.0/dist/chart.min.js"></script>
</body>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda