2017-01-11 55 views
1

我正在使用Django 1.10.3和python 3.4.2。
出於某種原因,chartit在我的圖表上不顯示圖形線。但是,當我在瀏覽器中查看源代碼時,我可以看到「數據」。請指出我錯在哪裏。Django Chartit不顯示yAxis數據

My圖表(無圖)

Graph

這裏是視圖源顯示

<head> 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> 
     <script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script> 
</head> 
<div id='cont'><script type="text/javascript"> 
var _chartit_hco_array = [{"yAxis": [{"title": {"text": "Temp"}}], "series": [{"stacking": false, "data": ["20.83", "20.83", "21.61", "22.11", "23.00", "23.17", "23.94", "24.67", "24.94", "24.94", "25.00", "25.00"], "type": "line", "name": "temperature"}], "xAxis": [{"categories": ["2016-12-16T11:40:13+00:00", "2016-12-16T11:40:13+00:00", "2016-12-16T12:00:32+00:00", "2016-12-16T12:20:51+00:00", "2016-12-16T13:20:56+00:00", "2016-12-16T13:40:22+00:00", "2016-12-16T14:00:41+00:00", "2016-12-16T14:21:00+00:00", "2016-12-16T14:40:26+00:00", "2016-12-16T14:47:29+00:00", "2016-12-16T14:51:02+00:00", "2016-12-16T14:54:34+00:00"], "title": {"text": "Date"}}], "chart": {"renderTo": "cont"}, "title": {"text": "Temp Data of Kedsum"}}]; 
</script> 
<script src="/static/chartit/js/chartloader.js" type="text/javascript"> 
</script></div> 

views.py

from chartit import DataPool, Chart 
from django.shortcuts import render 
from monitor.models import LogicLocation, SensorPrologue, SensorThgr122N, SensorKedsum 

#def graphs(request): 
# return render(request, 'graphs/graphs.html', {'content': ['Graphs Output!!!']}) 

def graphs(request): 
    #Step 1: Create a DataPool with the data we want to retrieve. 
    sensordata = DataPool(
      series= 
      [{'options': { 
       'source': SensorKedsum.objects.all()}, 
       'terms': [ 
       'date', 
       'temperature']} 
      ]) 

    #Step 2: Create the Chart object 
    cht = Chart(
      datasource = sensordata, 
      series_options = 
       [{'options':{ 
        'type': 'line', 
        'stacking': False}, 
       'terms':{ 
        'date': [ 
        'temperature'] 
        }}], 
      chart_options = 
       {'title': { 
        'text': 'Temp Data of Kedsum'}, 
       'xAxis': { 
        'title': { 
         'text': 'Date'}}, 
       'yAxis': { 
       'title': { 
        'text': 'Temp', 
       }}}) 

    #Step 3: Send the chart object to the template. 
    return render(request, 'graphs/graphs.html', {'tempchart': cht}) 

graphs.html

<head> 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> 
     <script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script> 
</head> 
{% load chartit %} 

{% block content %} 
      <div id='cont'>{{ tempchart|load_charts:"cont" }}</div> 
{% endblock %} 

這裏是控制檯輸出

Performing system checks... 

System check identified no issues (0 silenced). 
January 11, 2017 - 20:18:27 
Django version 1.10.3, using settings 'smarthome.settings' 
Starting development server at http://0.0.0.0:8000/ 
Quit the server with CONTROL-C. 
[11/Jan/2017 20:18:29] "GET /graphs/ HTTP/1.1" 200 1128 
[11/Jan/2017 20:18:30] "GET /static/chartit/js/chartloader.js HTTP/1.1" 304 0 

回答

0

問題的維護者是與模型字段類型。在我的情況下,它是VARCHAR,但它必須是DECIMAL或INTEGER

謝謝!

0

@Vams, 我看到你使用最新版本的HighCharts.js,這可能無法正常工作。使用Django-Chartit需要以下JavaScript庫。

  • jQuery - 版本1.6.4和1.7已知可與django-chartit配合使用。
  • Highcharts - 版本2.1.7和2.2.0已知可與django-chartit配合使用。

嘗試舊版本之一,看看它是否工作。如果確實如此,則意味着HighCharts.js的新版本與舊版本不兼容。如果連舊版本都不能正常工作,這意味着代碼中的某處出現問題。我將需要打開一個錯誤來進一步調試。

- 亞歷克斯,Django的chartit

+0

嗨亞歷克斯, 謝謝你的回覆,但它沒有幫助。 但是我發現問題是數據表示。請檢查此https://jsfiddle.net/r0yxkxbt/ 它看起來像**數據**中的引號產生問題。我有這個數據:「20.83」「20.83」「21.61」「22.11」「23.00」「23.17」「23.94」「24.67」「24.94」「24.94」 「25.00」,「25.00」],' ,但它與 數據一起使用:[20.83,20.83,21.61,22.11,23.00,23.17,23.94,24.67,24.94,24.94,25.00,25.00],' – Vams