Scatter plot with data from multiple models

We can do more complicated plots from multiple databases on the same chart. In this chart we plot a scatter plot of daily weather of Boston from the DailyWeather database and the monthly average temperature of Boston as a from the MonthlyWeatherByCity database on the same chart.

Points to note:

  • Notice that the data is filtered naturally using filter method in django.
  • The zIndex parameter (one of the many Highcharts series options) is used to force the monthly temperature to be on the top.

code

ds = DataPool(
       series=
        [{'options': {
            'source': DailyWeather.objects.filter(city="Boston")},
          'terms': [
            'month', 
            'temperature']},
         {'options': {
            'source': MonthlyWeatherByCity.objects.all()},
          'terms': [
            {'month_boston': 'month'}, 
            'boston_temp']}])

cht = Chart(
        datasource = ds, 
        series_options = 
          [{'options':{
              'type': 'scatter'},
            'terms':{
              'month': [
                'temperature']
              }},
           {'options':{
              'type': 'scatter',
              'zIndex': 1},
            'terms':{
              'month_boston': [
                'boston_temp']
              }},
           ],
        chart_options = 
          {'title': {
               'text': 'Boston Daily weather and Monthly Average'},
           'yAxis': {
             'title': {
               'text': 'Temperature'}}})