Pivot Chart with DateField

This chart shows total sales of one book per date.

Note that we filter down the possible values using date range queries instead of slicing. Slicing the query results in an error. Slicing in Chart() charts however is fine!

code

ds = PivotDataPool(
      series=[
       {'options': {
          'source': SalesHistory.objects.filter(
                        book=Book.objects.filter(title="Hyperspace"),
                        sale_date__year=2010,
                        sale_date__month=10,
                    ),
          'categories': 'sale_date'},
        'terms': {
          'tot_sales': Sum('sale_qty')}}])

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