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

203
Vistas
chartjs display data in one bar line with 3 different data sets in 3 different colors

I currently display my data like this: Click here

but I would like to display the data like this: Click here

The idea is that at the bottom it would show the summary of all three colors numbers combined, but once you hover it would show how much each color has.

If all is one bar, if red is 7, blue is 3, the red but be a lot more in the bar.

This is the code for version 1, done with chart js

var ctx = document.getElementById("myChart").getContext("2d");

var data = {
    labels: ["Chocolate", "Vanilla", "Strawberry"],
    datasets: [
        {
            label: "Blue",
            backgroundColor: "blue",
            data: [3, 7, 4]
        },
        {
            label: "Red",
            backgroundColor: "red",
            data: [4, 3, 5]
        },
        {
            label: "Green",
            backgroundColor: "green",
            data: [7, 2, 6]
        }
    ]
};

var myBarChart = new Chart(ctx, {
    type: 'bar',
    data: data,
    options: {
        barValueSpacing: 20,
        scales: {
            yAxes: [{
                ticks: {
                    min: 0,
                }
            }]
        }
    }
});

const myChart = new Chart(
    document.getElementById('myChart'),
    config
);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

your problem is the next, you are using a wrong config you must something like this:

<script src="https://cdn.jsdelivr.net/npm/chart.js@3.6.0/dist/chart.min.js"></script>

<canvas id="MyChart" width="400" height="200"></canvas>
<script>
new Chart(document.getElementById("MyChart"), {
  type: 'bar',
  data: {
    labels: [2017],
    datasets: [{
      label: "Chocolate",
      type: "bar",
      stack: "Base",
      backgroundColor: "#eece01",
      data: [30],
    }, {
      label: "Vanilla",
      type: "bar",
      stack: "Base",
      backgroundColor: "#87d84d",
      data: [-15],
    }, {
      label: "Strawberry",
      type: "bar",
      stack: "Base",
      backgroundColor: "#f8981f",      
      data: [20],
    }, {
      label: "candy",
      type: "bar",
      stack: "Base",
      backgroundColor: "#00b300",
      backgroundColorHover: "#3e95cd",
      data: [-10]
    }]
  },
  options: {
    plugins: {
      title: {
        display: true,
        text: 'Chart.js Bar Chart - Stacked'
      },
    },
    responsive: true,
    interaction: {
      intersect: false,
    },
    scales: {
      x: {
        stacked: true,
      },
      y: {
        stacked: true
      }
    }
  }
});
</script>

Now you just need to fix the styles and sizes of the graphic

about 4 years ago · Juan Pablo Isaza Denunciar

0

If someone finds this, the solution is this:

  const config = {
      type: 'bar',
      data: data,
      options: {
        plugins: {
          title: {
            display: true,
            text: 'Chart.js Bar Chart - Stacked'
          },
        },
        responsive: true,
        scales: {
          x: {
            stacked: true,
          },
          y: {
            stacked: true
          }
        }
      }
};
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