Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

391
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda