Django chartit加载jquery和highcharts js

时间:2014-11-11 23:59:18

标签: jquery django highcharts

我试图使用Chartit将一些图表包含到我的django网站但面临问题。为了简单起见,我创建了一个复制图表演示图表但仍然存在问题的项目。我猜这个问题与加载jquery和突出显示js有关。这就是我得到的。

模型

from django.db import models

class MonthlyWeatherByCity(models.Model):
    month = models.IntegerField()
    boston_temp = models.DecimalField(max_digits=5, decimal_places=1)
    houston_temp = models.DecimalField(max_digits=5, decimal_places=1)
    new_york_temp = models.DecimalField(max_digits=5, decimal_places=1)
    san_franciso_temp = models.DecimalField(max_digits=5, decimal_places=1)

class MonthlyWeatherSeattle(models.Model):
    month = models.IntegerField()
    seattle_temp = models.DecimalField(max_digits=5, decimal_places=1)

class DailyWeather(models.Model):
    month = models.IntegerField()
    day = models.IntegerField()
    temperature = models.DecimalField(max_digits=5, decimal_places=1)
    city = models.CharField(max_length=50)
    state = models.CharField

查看

from django.shortcuts import render_to_response
from chartit import DataPool,Chart
from demo.models import MonthlyWeatherByCity


def line(request):
ds = DataPool(
   series=
    [{'options': {
        'source': MonthlyWeatherByCity.objects.all()},
      'terms': [
        'month',
        'houston_temp', 
        'boston_temp']}
     ])

cht = Chart(
        datasource = ds, 
        series_options = 
          [{'options':{
              'type': 'line',
              'stacking': False},
            'terms':{
              'month': [
                'boston_temp',
                'houston_temp']
              }}],
        chart_options = 
          {'title': {
               'text': 'Weather Data of Boston and Houston'},
           'xAxis': {
                'title': {
                   'text': 'Month number'}}})

return render_to_response('demo/chart.html', {'weatherchart':cht})

模板

<html>
<head>
<script src ="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src ="http://code.highcharts.com/highcharts.js"></script>
{% load chartit %}
{{ weatherchart|load_charts:”container” }}
</head>
<body>
<div id=”container”>
</div>
</body>
</html>

并且在设置中我已经安装了以下内容

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'demo',
'jquery',
'highcharts',
'chartit', 
)

问题是当我尝试加载图表时收到以下消息

/ chart /上的TemplateSyntaxError 无法解析剩余部分:&#39;:“容器”&#39;来自&#39; weatherchart | load_charts:“container”&#39;

实际上,如果我从模板中删除脚本标记,我会收到相同的消息。我也尝试过本地版本的jquery和highcharts,或者使用相同的结果。有没有人知道我错过了什么?我一直在寻找不同的例子,看起来我正在以正确的方式做所有事情,还有什么我需要加载吗?谢谢你的帮助......

此致

亚历

1 个答案:

答案 0 :(得分:1)

更改引号:

{{ weatherchart|load_charts:”container” }} -->

{{ weatherchart|load_charts:"container" }}