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

255
Views
Chart Js , repeated labels yAxis

Y have this issue: User 1 repeats twice in two colors, gray and white. Gray should not be seen enter image description here

This problem starts when I put styles to the x axis, it repeats the labels. is there any solution for this case? The requirement is simply to change the color of the axis labels and ticks. The gray bar is at the bottom, that is, it does not stack with the red and blue ones

var data = {
  labels: ["User1", "User2"],
  datasets: [
      {
      stack:1,
      label: "TotalTime",
      backgroundColor: "red",
      borderWidth: 1,
      data: [50, 50],
      yAxisID:1
    },
    {
      stack:1,
      label: "TotalTime",
      backgroundColor: "blue",
      borderWidth: 1,
      data: [40, 40],
      yAxisID:1
    },
    {
      label: "Leave",
      backgroundColor: "rgba(191,191,191, 0.5)",
      borderWidth: 1,
      data: [100, 100],
      yAxisID:1
    },
  ],
};

var options = {
  indexAxis: "y",
  scales: {
      y: {
        ticks: {
          color: "white",
          font: {
            size: 12, 
          },
        },
        stacked: true,
      },
      x: {
        ticks: {
          color: "white",
          font: {
            size: 12, 
          },
        },
      }
  }
}

var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx, {
  type: 'bar',
  data: data,
  options: options
});
canvas{
  background-color:black
}
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.6.2/dist/chart.min.js"></script>
<canvas id="myChart" width="500" height="300"></canvas>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is because of your yAxisID, you dont define it but chart.js still makes a new axis for it since it isnt made by you with that id, so if you remove that or make it y which you have defined it doesnt make it again anymore

var data = {
  labels: ["User1", "User2"],
  datasets: [{
      label: "TotalTime",
      backgroundColor: "red",
      borderWidth: 1,
      data: [50, 50],
    },
    {
      label: "TotalTime",
      backgroundColor: "blue",
      borderWidth: 1,
      data: [40, 40],
    },
    {
      label: "Leave",
      backgroundColor: "rgba(191,191,191, 0.5)",
      borderWidth: 1,
      data: [100, 100],
    },
  ],
};

var options = {
  indexAxis: "y",
  scales: {
    y: {
      ticks: {
        color: "white",
        font: {
          size: 12,
        },
      },
      stacked: true,
    },
    x: {
      stacked: true,
      ticks: {
        color: "white",
        font: {
          size: 12,
        },
      },
    }
  }
}

var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx, {
  type: 'bar',
  data: data,
  options: options
});
canvas {
  background-color: black
}
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.6.2/dist/chart.min.js"></script>
<canvas id="myChart" width="500" height="300"></canvas>

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!