Django:如何在chartit模块的数据透视图中自定义我的数据

时间:2015-05-14 14:53:16

标签: django module

在django视图中我有:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if (this.readyState == 4 && this.status == 200){
        ...
        var blob = this.response; //save the blob as usual
        ...
    }
}
xhr.open('POST', 'reports/download');
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.responseType = 'blob'; // the response will be a blob and not text
xhr.send(jData);      

我使用females = Demographic.objects.filter(gender__startswith='f') males = Demographic.objects.filter(gender__startswith='m') 来显示每个性别的人数,换句话说就是显示chartitfemales.count()

您是否知道如何将我的数据自定义为males.count()透视图?

目前我的代码是下面的代码,但无效。

chartit

1 个答案:

答案 0 :(得分:1)

我找到了使用django聚合函数的解决方案。见下文:

ds = PivotDataPool(
    series=[
        {'options': {
            'source':Demographic.objects.all(),
            'categories':['gender'] },
            'terms':{
                'sex_count':Count('gender'),
                }
        }
    ]
)

pvcht = PivotChart(
    datasource=ds,
    series_options =
          [{'options':{
            'type': 'column',
            #'stacking': True
            },
            'terms':[
            'sex_count']}],
     chart_options =
          {'title': {
               'text': 'Total number'},
           'xAxis': {
                'title': {
                   'text': 'Sex'}}}
)