Django-Chartit2 'dict_keys' object does not support indexing 报错
Django-Chartit2 'dict_keys' object does not support indexing error
我正在按照提供的演示示例探索用于图表目的的 Django Chartit2 包 here。我已经创建了自己的数据透视图模型,其中包含以下字段:城市、人员和销售额。
在我看来,我正在通过使用基于销售列聚合的术语来创建数据透视图。
在尝试访问 url 时出现错误:
Exception Type: TypeError at /chart/pivotpool/
Exception Value: 'dict_keys' object does not support indexing
让我知道在指定数据透视图的条款时我遗漏了什么。
class SalesHistory(models.Model):
city = models.CharField(max_length=50)
person = models.CharField(max_length=50)
sales_qty = models.IntegerField()
def some_view(request):
ds = PivotDataPool(series=[{'options': {'source': SalesHistory.objects.all(), 'categories': ['city']},
'terms': {'total_sales': Sum('sales_qty')}}])
pivchrt = PivotChart(datasource=ds, series_options=[{'options': {'type': 'column', 'stacking': True}, 'terms':['total_sales']}], chart_options = {})
我的回溯:
Traceback:
File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/sam/Documents/Lab Projects/djangoChartit/demoChartit/views.py" in some_view
131. 'text': 'city'}}})
File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/chartit/charts.py" in __init__
508. self.set_default_hcoptions()
File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/chartit/charts.py" in set_default_hcoptions
533. categories = dss[terms[0]]['categories']
chartit charts.py 文件中 set_default_hcoptions 函数中使用的术语没有属性索引,这就是它给我错误的原因。我已经评论了它被初始化的行,即
# terms = self.series_options.keys()
并添加了我自己的版本:
terms = list(self.series_options)
它对我有用。
我正在按照提供的演示示例探索用于图表目的的 Django Chartit2 包 here。我已经创建了自己的数据透视图模型,其中包含以下字段:城市、人员和销售额。
在我看来,我正在通过使用基于销售列聚合的术语来创建数据透视图。
在尝试访问 url 时出现错误:
Exception Type: TypeError at /chart/pivotpool/
Exception Value: 'dict_keys' object does not support indexing
让我知道在指定数据透视图的条款时我遗漏了什么。
class SalesHistory(models.Model):
city = models.CharField(max_length=50)
person = models.CharField(max_length=50)
sales_qty = models.IntegerField()
def some_view(request):
ds = PivotDataPool(series=[{'options': {'source': SalesHistory.objects.all(), 'categories': ['city']},
'terms': {'total_sales': Sum('sales_qty')}}])
pivchrt = PivotChart(datasource=ds, series_options=[{'options': {'type': 'column', 'stacking': True}, 'terms':['total_sales']}], chart_options = {})
我的回溯:
Traceback: File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response 149. response = self.process_exception_by_middleware(e, request) File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response 147. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/sam/Documents/Lab Projects/djangoChartit/demoChartit/views.py" in some_view 131. 'text': 'city'}}}) File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/chartit/charts.py" in __init__ 508. self.set_default_hcoptions() File "/home/sam/Documents/onemoreEnv/lib/python3.4/site-packages/chartit/charts.py" in set_default_hcoptions 533. categories = dss[terms[0]]['categories']
chartit charts.py 文件中 set_default_hcoptions 函数中使用的术语没有属性索引,这就是它给我错误的原因。我已经评论了它被初始化的行,即
# terms = self.series_options.keys()
并添加了我自己的版本:
terms = list(self.series_options)
它对我有用。