Pivot chart with only top few items

Pivot Chart limited to top few items. In this chart the sales quanity is plotted w.r.t state/city but the chart is limited to only top 5 cities witht the highest sales.

Points to note:

  • These charts are helpful in cases where there is a long tail and we only are interested in the top few items.
  • top_n_term is always required. If there are multiple items, it will elimnate confusion regarding what the term the chart needs to be limited by.


ds = PivotDataPool(
      series= [
          'source': SalesHistory.objects.all(),
          'categories': [
          'legend_by': 'book__genre__name'},
        'terms': {
      top_n = 5,
      top_n_term = 'tot_sales')

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