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

262
Views
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 answers
Answer question

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