所以,我試圖用我的數據創建一個數據透視表,但我一直得到'NoneType'對象不可迭代。我正在使用Chartit。我的錯誤與「術語」,具體爲:[「tot_ft」]}])這是專門在數據透視圖部分'NoneType'對象在Chartit中是不可迭代的
這裏是我的代碼: 這裏是下面的事情我已經導入:
from django.shortcuts import render, get_list_or_404, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from basketball.models import Stats, Player, League, Game, Team
from django.contrib.auth import get_user
from django.db.models import Sum
from django.http import HttpResponse, HttpResponseRedirect
from django.core.mail import send_mail, BadHeaderError
from chartit import PivotDataPool, PivotChart
views.py中
def player_pivot_chart_view(request):
# Step 1: Create a PivotDataPool with the data we want to retrieve
playerPivotData = PivotDataPool(
series =
[{'options': {
'source': Stats.objects.all(),
'categories': 'player__first_name'},
'terms': {
'tot_ft':Sum('freeThrowsMade')}}])
pivcht = PivotChart(
datasource = playerPivotData,
series_options = [
{'options': {
'type': 'column',
'stacking': True},
'terms': ['tot_ft']}])
return render(request,'basketball/StatsPage.html', {'dataChart':pivcht})
models.py
class Stats(models.Model):
player = models.ForeignKey(Player)
game = models.ForeignKey(Game)
freeThrowsMade = models.PositiveIntegerField(verbose_name='FTm', default = 0)
freeThrowsAttempted = models.PositiveIntegerField(verbose_name='FTa', default = 0)
twoPointsMade = models.PositiveIntegerField(verbose_name='2Pm', default = 0)
twoPointsAttempted = models.PositiveIntegerField(verbose_name='2Pa', default = 0)
threePointsMade = models.PositiveIntegerField(verbose_name='3Pm', default = 0)
threePointsAttempted = models.PositiveIntegerField(verbose_name='3Pa', default = 0)
blocks = models.PositiveIntegerField(default = 0)
steals = models.PositiveIntegerField(default = 0)
assists = models.PositiveIntegerField(default = 0)
fouls= models.PositiveIntegerField(default = 0)
你也可以添加追溯 – dusual 2013-04-25 18:55:20
你可以去這個鏈接http://dpaste.com/1073522/ – 2013-04-25 18:59:11
我有一個問題一個單一的領域的總和應該給1個數據點,你只有一個單一的術語/軸你正在這個圖表你想用一個數據點來繪製圖表,你必須有更多的相對位置來創建一個圖表 – dusual 2013-04-25 19:11:44