Django: how to customize my data in pivot chart of chartit module -
in django view have:
females = demographic.objects.filter(gender__startswith='f') males = demographic.objects.filter(gender__startswith='m') i use chartit have graph number of people per sex, in other words show females.count() , males.count().
do have idea how customize data chartit pivot chart?
currently code 1 below not working.
ds = pivotdatapool( series=[ {'options': { 'source':demographic.objects.filter(gender__startswith='f'), 'categories':['gender'] }, 'terms':{ 'sex_count':females.count(), } } ] ) pvcht = pivotchart( datasource=ds, series_options = [{'options':{ 'type': 'column', 'stacking': true}, 'terms':[ 'sex_count']}], chart_options = {'title': { 'text': 'total number'}, 'xaxis': { 'title': { 'text': 'sex'}}} )
i found solution using django aggregate function. see below:
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'}}} )
Comments
Post a Comment