【问题标题】:Django chartit loading jquery and highcharts jsDjango chartit 加载 jquery 和 highcharts js
【发布时间】:2015-05-29 16:24:43
【问题描述】:

我正在尝试使用 Chartit 在我的 django 网站中包含一些图表,但遇到了问题。为了简单起见,我创建了一个复制 chartit 演示图表但仍然存在问题的项目。我猜这个问题与加载 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/ 处的模板语法错误 无法解析来自 'weatherchart|load_charts:”container”' 的剩余部分:':”container”'

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

问候,

亚历杭德罗

【问题讨论】:

    标签: jquery django highcharts


    【解决方案1】:

    更改引号符号:

    来自 {{ weatherchart|load_charts:”container” }} --&gt;

    {{ weatherchart|load_charts:"container" }}

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 2018-07-18
      • 2013-05-13
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      相关资源
      最近更新 更多