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

113
Views
How can I access a variable from the drawChart function of GoogleChartsNode?

Here the example of my code.

    var question = {question: "Q 1. What is your name?", value: "name"}; 
    
    const getImage = async () => {
      const image = await GoogleChartsNode.render(drawChart, {
        width: 400,
        height: 300,
      });
      fs.writeFileSync("./image.png", image, "binary");
    }

    const drawChart = async () => {
      const data = google.visualization.arrayToDataTable([
        ["Class", "Students", { role: 'style' }],
        ['5', 1, "color: red"],
        ['4', 2, "color: orange"],
        ['3', 3, "color: blue"],
        ['2', 3, "color: green"],
        ['1', 1, "color: rgb(152, 240, 149)"]
      ]);
    
      const options = {
       title: question.question,
       chartArea: { width: '50%' },
       hAxis: {
        title: "# Ratings",
        minValue: 0,
        maxValue: 10
      },
      vAxis: {
       title: "# Percentage"
      }
   };
 }

This is an example of my code. I want to access the object question from the drawChart function. But it isn't accessible.

It is giving an error like this.

Page error: Error: ReferenceError: question is not defined
    at drawChart (about:blank:22:12)
    at drawChartFn (about:blank:38:11)
    at about:blank:45:24
about 4 years ago · Juan Pablo Isaza
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!