Hi, thanks for taking your time to reply.
I already tried the count method as u mentioned in the views.py
but I’m not sure how to call it in the template? Do I need to convert it into JSON or just call it just like that? but Im still not sure if im doing it right… it still doesn’t display any chart.
Im quite confused on how to call the data in the page and how to put it in the chart data script.
The comments are the bunch of stuff I tried but also failed… Can show me how to do it?
<!-- {{ list_of_tweets_and_sentiments|json_script:"list_of_tweets_and_sentiments" }}
{{ pos|json_script:"pos-data" }}
{{ neu|json_script:"neu-data" }}
{{ neg|json_script:"neg-data" }} -->
<!-- <script id="pos-data" type="application/json">{'pos':pos}</script>
<script id="neu-data" type="application/json">{'neu':neu}</script>
<script id="neg-data" type="application/json">{'neg':neg}</script> -->
<canvas id="list_of_tweets_and_sentiments" width="90" height="90"></canvas>
<script id="list_of_tweets_and_sentiments" type="application/json">{{pos}},{{neu}},{{neg}}</script>
<script>
// const ctx = JSON.parse(document.getElementById('pos-data','neu-data','neg-data')).getContext('2d');
// const ctx = JSON.parse(document.getElementById('pos-data','neu-data','neg-data')).getContext('2d');
const ctx = document.getElementById('list_of_tweets_and_sentiments').getContext('2d');
const list_of_tweets_and_sentiments = new Chart(ctx, {
// const myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Positive', 'Neutral', 'Negative'] ,
datasets: [{
label: 'Sentiment Counts',
data: pos,neu,neg,
backgroundColor: [
'green',
'orange',
'red',
],
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script></div>