Django chartit 2多系列单通道

2024-10-01 00:23:01 发布

您现在位置:Python中文网/ 问答频道 /正文

在成功地使用Django Chartit 2构建图形(简单的折线图和Pivot图表的不同用法)之后,我尝试用来自不同模型的数据制作折线图。它失败了,我试图复制示例provided here

它也失败了,我想知道为什么,我猜测它可能与chartit2的python3迁移(我使用python3.5/django1.8/chartit0.2.2)有关,如果从chartit1文档中得到的话。也许它还没有被改编成Python3,但我不能解决这个问题。。。这是我的代码:

  • 视图:与提供的示例完全相同
  • 回溯:

TypeError at /space/reports/2

unorderable types: dict() < dict()

Request Method: GET

Request URL: http://localhost:8000/space/reports/2

Django Version: 1.8.6

Exception Type: TypeError

Exception Value:

unorderable types: dict() < dict()

Exception Location: C:\Program Files (x86)\Python 3.5\lib\site->packages\chartit\charts.py in _groupby_x_axis_and_vqs, line 159

  • 完全回溯:

C:\Program Files (x86)\Python 3.5\lib\site-packages\django\core\handlers\base.py in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) ...

C:\Users\Usuario1\space\reports\views.py in reports3 'text': 'Month number'}}}) ...

C:\Program Files (x86)\Python 3.5\lib\site-packages\chartit\charts.py in init self.x_axis_vqs_groups = self._groupby_x_axis_and_vqs() ...

C:\Program Files (x86)\Python 3.5\lib\site-packages\chartit\charts.py in _groupby_x_axis_and_vqs itr1 = sorted(itr1, key=sort_fn)

  • chartit中对应的代码\图表.py公司名称:

    dss = self.datasource.series
    x_axis_vqs_groups = defaultdict(dict)
    sort_fn = lambda td_tk: td_tk[1].get('xAxis', 0)
    so = sorted(self.series_options.items(), key=sort_fn)
    x_axis_groups = groupby(so, sort_fn)
    for (x_axis, itr1) in x_axis_groups:
        sort_fn = lambda td_tk: dss[td_tk[1]['_x_axis_term']]['_data']
                    **itr1 = sorted(itr1, key=sort_fn)**
        for _vqs_num, (_data, itr2) in enumerate(groupby(itr1, sort_fn)):
            x_axis_vqs_groups[x_axis][_vqs_num] = _x_vqs = {}
            for tk, td in itr2:
                _x_vqs.setdefault(td['_x_axis_term'], []).append(tk)
    return x_axis_vqs_groups
    

如果你能帮忙,非常感谢!在


Tags: inpyfilesprogramsortdictx86tk
1条回答
网友
1楼 · 发布于 2024-10-01 00:23:01

也许亚历山大·托多罗夫的这篇文章可能有助于:

The problem is that the second elements in both lists have different keys and Python doesn't know how to compare them. In earlier Python versions this has been special cased as described here by Ned Batchelder (the author of Python's coverage tool) but in Python 3 dictionaries have no natural sort order. In the case of django-chartit (of which I'm now the official maintainer) this bug triggers when you want to plot data from multiple sources (models) on the same chart. In this case the fields coming from each data series are different and the above error is triggered.

指向错误描述的链接:http://atodorov.org/blog/2016/08/05/python-2-vs-python-3-list-sort-causes-bugs/

相关问题 更多 >