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

145
Vistas
Change the hover data value from to string

I have a bar chart with typical data being: data: [1, 3, 4, 2] When I hover over the data bar, I would like the values to display text, where a 1 corresponds to "start", 2 is "partial", etc. How can I accomplish this? There seem to be several similar questions and answers about tooltips but I haven't been able to implement this. My bar chart code is:

const options = {
      scales: {
        x: {
          grid: {
            display: false,
          }
        },
        y: {
          display: false
        },
      }
    };
    
var config = {
  type: 'bar',
  data: {
    labels: ['date 1','date 2','date 3','date 4'],
    datasets: [{
      data: [3, 2, 1, 3],
      label: chart 1,
      borderWidth: 1
    }]
  },
  options: options,
}
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, config);

And I tried adding the tooltips code:

const options = {
      scales: {
        x: {
          grid: {
            display: false,
          }
        },
        y: {
          display: false
        },
      },
      plugins: {
          tooltips: {
              callbacks: {
                title: function(tooltipItems, data) {
                  return 'test';
                },
                label: function(tooltipItem, data) {
                  return 'test 2';
                }
              }
          }
      },
    };

If I can get the test to show up on the tooltip, I think I can do the rest using something like:

myValue = '';
switch (data) {
    case 1:
        myValue = 'start';
        break;
    case 2:
        myValue = 'partial'
        break;
    ....
return myValue;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In v3 the name of the tooltip config has changed from tooltips to tooltip:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      borderWidth: 1
    }]
  },
  options: {
    plugins: {
      tooltip: {
        callbacks: {
          label: (val) => {
            return val.label + ' test ' + val.parsed.y
          }
        }
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.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