Commit 0efa93bf authored by Kristian Tan's avatar Kristian Tan

Test bar chart

parent d9cdc017
...@@ -109,7 +109,19 @@ def main(): ...@@ -109,7 +109,19 @@ def main():
'display_change_kWh': False 'display_change_kWh': False
} }
return render_template('main.html', **template_data) labels = [
'JAN', 'FEB', 'MAR', 'APR',
'MAY', 'JUN', 'JUL', 'AUG',
'SEP', 'OCT', 'NOV', 'DEC'
]
values = [
967.67, 1190.89, 1079.75, 1349.19,
2328.91, 2504.28, 2873.83, 4764.87,
4349.29, 6458.30, 9907, 16297
]
return render_template('main.html', **template_data, labels=labels, values=values)
@app.route("/toggle/<change_pin>") @app.route("/toggle/<change_pin>")
......
...@@ -67,6 +67,47 @@ ...@@ -67,6 +67,47 @@
{% endif %} {% endif %}
</div> </div>
<canvas id="chart" width="600" height="400"></canvas>
<script>
// bar chart data
var barData = {
labels : [
{% for item in labels %}
"{{ item }}",
{% endfor %}
],
datasets : [{
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
data : [
{% for item in values %}
"{{ item }}",
{% endfor %}
]
}
]
}
// get bar chart canvas
var mychart = document.getElementById("chart").getContext("2d");
steps = 10
max = {{max}}
// draw bar chart
new Chart(mychart).Bar(barData, {
scaleOverride: true,
scaleSteps: steps,
scaleStepWidth: Math.ceil(max / steps),
scaleStartValue: 0,
scaleShowVerticalLines: true,
scaleShowGridLines : true,
barShowStroke : true,
scaleShowLabels: true
}
);
</script>
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment