2017-02-16 18 views
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

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 %} 
+0

私は完全なトレースバックを追加しました – Percy3872

答えて

0

はあなたのURLパターンではなく、クラスLineChartでビューsome_viewを使用する必要があります。

url(r'^polls/bubble/$', views.some_view, name='bubble'), 

また、some_viewためのインデントが正しいことを確認してください。あなたの実際のコードの代わりにあなたの質問に間違いがあるかもしれませんが、現在はsome_viewLineChartクラスのメソッドとして持っています。それは次のとおりです:

class LineChart(Chart): 
    chart_type = 'line' 
    responsive = False 
    ... 

def some_view(request): 
    render(request, 'polls/chart.html', { 
    'line_chart': LineChart(), 
}) 
関連する問題