2
我想在django中製作折線圖,我正在使用jchart模塊,當我嘗試加載圖表時出現以下錯誤。django'LineChart'對象沒有屬性'get'
錯誤 '線型圖' 對象有沒有屬性 '得到'
完全回溯
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/utils/deprecation.py", line 138, in __call__
response = self.process_response(request, response)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/clickjacking.py", line 32, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'LineChart' object has no attribute 'get'
視圖
from jchart import Chart
from jchart.config import Axes, DataSet, rgba
class LineChart(Chart):
chart_type = 'line'
responsive = False
scales = {
'xAxes': [Axes(type='time', position='bottom')],
}
def get_datasets(self, **kwargs):
data = [{'y': 0, 'x': '2017-01-02T00:00:00'}, {'y': 1, 'x': '2017-01-03T00:00:00'}, {'y': 4, 'x': '2017-01-04T00:00:00'}, {'y': 9, 'x': '2017-01-05T00:00:00'}, {'y': 16, 'x': '2017-01-06T00:00:00'}, {'y': 25, 'x': '2017-01-07T00:00:00'}, {'y': 36, 'x': '2017-01-08T00:00:00'}, {'y': 49, 'x': '2017-01-09T00:00:00'}, {'y': 64, 'x': '2017-01-10T00:00:00'}, {'y': 81, 'x': '2017-01-11T00:00:00'}, {'y': 100, 'x': '2017-01-12T00:00:00'}, {'y': 121, 'x': '2017-01-13T00:00:00'}, {'y': 144, 'x': '2017-01-14T00:00:00'}, {'y': 169, 'x': '2017-01-15T00:00:00'}, {'y': 196, 'x': '2017-01-16T00:00:00'}, {'y': 225, 'x': '2017-01-17T00:00:00'}, {'y': 256, 'x': '2017-01-18T00:00:00'}, {'y': 289, 'x': '2017-01-19T00:00:00'}, {'y': 324, 'x': '2017-01-20T00:00:00'}, {'y': 361, 'x': '2017-01-21T00:00:00'}, {'y': 400, 'x': '2017-01-22T00:00:00'}, {'y': 441, 'x': '2017-01-23T00:00:00'}, {'y': 484, 'x': '2017-01-24T00:00:00'}, {'y': 529, 'x': '2017-01-25T00:00:00'}, {'y': 576, 'x': '2017-01-26T00:00:00'}, {'y': 625, 'x': '2017-01-27T00:00:00'}, {'y': 676, 'x': '2017-01-28T00:00:00'}, {'y': 729, 'x': '2017-01-29T00:00:00'}, {'y': 784, 'x': '2017-01-30T00:00:00'}, {'y': 841, 'x': '2017-01-31T00:00:00'}, {'y': 900, 'x': '2017-02-01T00:00:00'}]
return [DataSet(
type='line',
label='Time Series',
data=data,
)]
def some_view(request):
render(request, 'polls/chart.html', {
'line_chart': LineChart(),
})
網址
url(r'^polls/bubble/$', views.LineChart, name='bubble'),
chart.h TML
{% extends "base.html" %}
{% load jchart %}
{% block content %}
{{ line_chart.as_html }}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
{% endblock %}
我添加了完整的回溯 – Percy3872