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

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

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 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