我正在尝试设置Chart.js以在我的项目中使用。这是我正在尝试复制的example,我使用的是PyCharm,所以很容易下载所有的库,并且我在安装的ap中添加了chart.js
我的test.html:
{% load staticfiles %}
<html>
<head>
<title>django-chartjs line chart demo</title>
<!--[if lte IE 8]>
<script src="{% static 'js/excanvas.js' %}"></script>
<![endif]-->
</head>
<body>
<h1>Some Line Charts loaded in Ajax!</h1>
<canvas id="myChart" width="500" height="400"></canvas>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script type="text/javascript" src="{% static 'js/Chart.min.js' %}"></script>
<script type="text/javascript">
$.get('{% url "line_chart_json" %}', function(data) {
var ctx = $("#myChart").get(0).getContext("2d");
new Chart(ctx, {
type: 'line', data: data
});
});
</script>
</body>
</html>我的观点是:
class LineChartJSONView(BaseLineChartView):
def get_labels(self):
"""Return 7 labels for the x-axis."""
return ["January", "February", "March", "April", "May", "June", "July"]
def get_providers(self):
"""Return names of datasets."""
return ["Central", "Eastside", "Westside"]
def get_data(self):
"""Return 3 datasets to plot."""
return [[75, 44, 92, 11, 44, 95, 35],
[41, 92, 18, 3, 73, 87, 92],
[87, 21, 94, 3, 90, 13, 65]]
line_chart = TemplateView.as_view(template_name='main/mark/test.html')
line_chart_json = LineChartJSONView.as_view()发布于 2018-05-31 00:54:41
因为您正在查看json结果;您正在执行如下操作:
http://localhost:8000/yourapp/line_chart/json你应该做的事情:
http://localhost:8000/yourapp/line_charthttps://stackoverflow.com/questions/50251069
复制相似问题