Pivot chart with top few items per category

Pivot Chart each category limited to a select top items.

Points to note:

  • These charts are helpful when there are too many items in each category and we only want to focus on the top few items in each category.

code

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

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