Pivot chart with multiple categories

Pivot Chart with multiple categories. In this chart the total sale quantity is plotted with respect to state and city.

Points to note:

  • You can add any number of categories and legend_by entries in a list.
  • Order matters! Retrieving state and then city may yield different results compared to retrieving city and state depending on what you are trying to plot.

code

ds = PivotDataPool(
      series= [
       {'options':{
          'source': SalesHistory.objects.all(),
          'categories': [
            'bookstore__city__state',
            'bookstore__city__city'],
          'legend_by': 'book__genre__name'},
        'terms': {
          'tot_sales':Sum('sale_qty')}}])

pivcht = PivotChart(
          datasource = ds, 
          series_options = [
            {'options': {
               'type': 'column',
               'stacking': True, 
               'xAxis': 0,
               'yAxis': 0},
             'terms': ['tot_sales']}])