I’m trying to create the chart by using chart.js from the client side. This is how I use it on my show page for individual polls:
<div class="col-md-4">
<b><span class="fa fa-sliders"></span> <%= poll.title %></b>
<form action="/poll/<%= poll._id %>" method="post">
<% poll.options.forEach(function(option) { %>
<input type="radio" name="option" value="<%= option.desc %>"> <%= option.desc %><br>
<% }); %>
<input type="text" name="newOption" placeholder="New Option" value=""><br>
<input class = "btn btn-danger" type="submit" value="Vote">
</form>
</div>
<div class="col-md-8">
<h2>Chart goes here</h2>
<canvas id="myChart" width="400" height="400"></canvas>
<ul>
<% poll.options.forEach(function(option) { %>
<li><%= option.desc %>: <%= option.votes %></li>
<% }); %>
</ul>
</div>
</div>
my question is the last line of that client side js, when I try to send the poll data to the console…it can’t access the data. yet “poll” object is what is sent to the show.ejs page from the server side. How can I access the poll data from this included javascript page in order to use my data rather than the boiler plate?