Data from multiple models on same chart

This example demonstrates data from two different models MonthlyWeatherByCity and MonthlyWeatherSeattle on the same chart and on the same x-axis.

Points to note:

  • The month in terms for seattle data is written as {'month_seattle': 'month'} instead of as just 'month' because in the latter case it would overwrite the 'month' term from the other model.
  • Notice that the Seattle weather data in the database does not have any data for August (8) and September (9). Chartit gracefully skips them and plots the rest of the data points aligned correctly.


ds = DataPool(
        [{'options': {
            'source': MonthlyWeatherByCity.objects.all()},
          'terms': [
         {'options': {
            'source': MonthlyWeatherSeattle.objects.all()},
          'terms': [
            {'month_seattle': 'month'},

cht = Chart(
        datasource = ds, 
        series_options = 
              'type': 'line',
              'stacking': False},
              'month': [
              'month_seattle': [
        chart_options = 
          {'title': {
               'text': 'Weather by Month (from 2 different tables)'},
           'xAxis': {
                'title': {
                   'text': 'Month number'}}})