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

257
Vistas
Call ChartJS details in main Javascript file

I have a Charts JS chart. I am able to click on the chart and show some chart info that id like to see like so:

onClick: (evt, activeEls, chart) => {
    
    alert(chart.data.labels[activeEls[0].index]);

},

My chartJS script currently lives in the html file. However, when I try and move this into my main.js it doesn’t work (i.e the function doesn’t run). I cant seem to figure out why.

The set up is like so:

Main.JS:

function show_info() { 
alert(chart.data.labels[activeEls[0].index]);
}

And I have changed that chartJS section in my HTML file to:.

onClick: (evt, activeEls, chart) => {
    show_info();
    
},

How can I set it so that the function lives in my Main.js file?

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

0

I think the variable chart is unknown in the scope of main.js. Therefore, you would need to provide the chart variable to show_info like so:

// main.js
function show_info(my_object) { 

alert(my_object.data.labels[activeEls[0].index]);
}

// other file
onClick: (evt, activeEls, chart) => {
    show_info(chart);
    
},
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