1
graphs.html 


{% extends "base.html" %}
<script type = "text/javascript" src = "{{ STATIC_URL }}js/highcharts.js"></script>
<script type = "text/javascript" src = "{{ STATIC_URL }}js/jquery-1.9.1.min.js">                                                                                                                                                 </script>
<body >
{% block menu %}
{{block.super}}
{% endblock menu %}

{% block content %}
 {{weatherchart}}


<!-- code to include the highcharts and jQuery libraries goes here -->
<!-- load_charts filter takes a comma-separated list of id's where -->
<!-- the charts need to be rendered to                             -->
{% load chartit %}
{{ weatherchart|load_charts:"container" }
 <div id='container'>  </div>
  {% endblock content %}
</body>



views.py


def plot_graph(request):
month_number=[]
months=KEBReading.objects.filter().values("datetime_reading")
print months
for obj in months:
    month_number=obj["datetime_reading"].day
    print month_number
#Step 1: Create a DataPool with the data we want to retrieve.
weatherdata = \
    DataPool(
       series=
        [{'options': {
           'source': KEBReading.objects.filter().values("id","truepower_consumed","voltage_reading")},
          'terms': [
            'id',
            'truepower_consumed','voltage_reading'
           ]}])





#Step 2: Create the Chart object
cht = Chart(
        datasource = weatherdata,
        series_options =
          [{'options':{
              'type': 'line',
              'stacking': False},
            'terms':{
              'id': [
                'truepower_consumed','voltage_reading']


              }}],

        chart_options =
          {'title': {
               'text': 'Graph For Power Management'},
           'xAxis': {
                'title':{'text': 'month_number'}}})
print "weather chart"
print cht

#Step 3: Send the chart object to the template.
return render_to_response('graph.html',{'weatherchart': cht},context_instance=RequestContext(request))

Django-Chartitの使用に問題があります。データベースのデータを使用してグラフを作成したいと考えています。私は上記のようにしました。しかし、グラフは表示されていません。私はそれを正しい方法でやっていますか?ヘルプをいただければ幸いです。前もって感謝します。テンプレートに他に欠けているものはありますか?(graphs.html)

4

2 に答える 2

0

私は同じ問題を抱えていて、どこにも文書化されていないソリューションに遭遇しました.

<div id="container">{{ chart|load_charts:"container" }}</div>

また、上記のように単一の代わりに、DIV ID の HTML で二重引用符を使用することをお勧めします。

于 2013-04-11T02:37:23.597 に答える