'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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source