Example shows Python Chart plotted using data that's fetched from database. It also includes Django MVT source-code that you can try running locally.
<!-- index.html -->
{% load static %}
<html>
<head>
<title>CanvasJS Python Charts</title>
<script>
window.onload = function () {
var data = {{ datapoints|safe }};
var dataPoints = []
for(var i=0; i<data.length; i++) {
dataPoints.push({x: data[i].fields.x, y: data[i].fields.y})
}
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Python Chart from Database",
fontFamily: "Trebuchet MS, Helvetica, sans-serif"
},
data: [{
type: "column",
dataPoints: dataPoints
}]
});
chart.render();
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 320px; width: 570px;"></div>
<script src="{% static 'canvasjs.min.js' %}"></script>
</body>
</html>
Chart title can be styled by setting fontColor, fontSize, fontStyle, fontWeight, fontFamily properties.