user3851205
user3851205

Reputation: 75

Django chartit loading jquery and highcharts js

I'm trying to include some charts to my django website using Chartit but facing problems. Just to keep it simple, I created a project that replicates chartit's demo charts but still having problems. I guess the problem is related with loading jquery and highlights js. Here's what I got.

Model

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

View

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})

Template

<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>

and in setting I have inside installed apps the following

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

The problem is that when I try to load the chart I received the following message

TemplateSyntaxError at /chart/ Could not parse the remainder: ':”container”' from 'weatherchart|load_charts:”container”'

Actually, if I remove the script tags from the template I receive the same message. I've also tried with local versions of jquery and highcharts or with the same results. Does anybody have an idea of what am I missing? I've been looking around at different examples and looks like I'm doing everything the right way, is there anything else I need to load? Thanks for your help guys...

Regards,

Alejandro

Upvotes: 0

Views: 745

Answers (1)

Joe
Joe

Reputation: 233

Change the quotation symbols:

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

TO {{ weatherchart|load_charts:"container" }}

Upvotes: 1

Related Questions