Last active
May 22, 2019 21:18
-
-
Save crawftv/ab93a72ff0d0ba53eafd2a7cde601fab to your computer and use it in GitHub Desktop.
JavaScript-jinja-html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--make the html element to contain the chart.--> | |
<canvas id="line-chart" width="3" height="1"></canvas> | |
{% block javascript %} | |
<script> | |
// load the objects like you would with a normal jinja template i.e. {{ object }}, but add | tojson | |
// pass it into the parse function | |
labels = JSON.parse({{ labels | tojson }}) | |
data = JSON.parse({{ data | tojson }}) | |
new Chart(document.getElementById("line-chart"),{ | |
"type":"line", | |
"data": | |
//using the labels here. | |
{"labels":labels, | |
"datasets":[{"label":"Sentiment Over Time", | |
//using data here | |
"data": data, | |
"fill":false, | |
"borderColor":"rgb(75, 192, 192)", | |
"lineTension":0.1}]}, | |
"options":{}}); | |
</script> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment