Home>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Question</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js" type="text/javascript"></script>
</head>
<body>
  Q:<%= question.content %>
<p>A:<%= question.countA %></p>
<p>B:<%= question.countB %></p>
  Next question
<canvas width="400" height="400"></canvas>
<script type="module">
    // ▼ Graph contents
    var pieData = [
       {
          value: "I want to pass data here", // value
          color:"#F7464A", // color
          highlight: "#FF5A5E", // color when mouse is over
          label: "A" // label
       },
       {
          value: "I want to pass data here",
          color: "#41C44E",
          highlight: "#6CD173",
          label: "B"
       },
    ];
    // ▼ description to draw the above graph
    window.onload = function(){
       var ctx = document.getElementById("graph-area").getContext("2d");
       window.myPie = new Chart(ctx).Pie(pieData);
    };
</script>
</body>
</html>

In the above ejs file, we pass the variable question from the server side and display it in the browser. I also want to pass the data of the variable question inside the script tag as well. What kind of method can be considered?

Chart.js is used for the graph drawing library.

If i have any questions, thank you.

Addendum
<body>
  Q:<%= question.content %>
<p>A:<%= question.countA %></p>
<p>B:<%= question.countB %></p>
  Next question
<canvas width="400" height="400"></canvas>
<% const countA = JSON.stringify(question.countA) %>
<% const countB = JSON.stringify(question.countB) %>
<script>
      // ▼ Graph contents
      var pieData = [
      {
         value: parseInt(countA), // value
         color:"#F7464A", // color
         highlight: "#FF5A5E", // color when mouse is over
         label: "A" // label
      },
      {
         value: parseInt(countB),
         color: "#41C44E",
         highlight: "#6CD173",
         label: "B"
      },
   ];
   // ▼ description to draw the above graph
   window.onload = function(){
      var ctx = document.getElementById("graph-area").getContext("2d");
      window.myPie = new Chart(ctx).Pie(pieData);
   };
</script>
</body>


I tried converting the variable I want to pass to the script to JSON as above, but it does not work.

I don't know why it's valid to convert a variable on ejs to JSON when passing it to a script, so I think I'm doing something meaningless.

It seems that Expression expected. occurs in any way when using the% tag in the script.