In [1]:
import pygal
from IPython.display import SVG, display
from memair import Memair
# Use Otto the sandbox user's access token or create your own at https://memair.com/temporary_access_token
access_token = '0000000000000000000000000000000000000000000000000000000000000000'

user = Memair(access_token)
In [2]:
response = user.query('''
    mutation { 
      CreateInsight(
        chart: {
          title: "Social Media Usage"
          type: line
          category_axis: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
          series: [
            {label: "facebook" data: [2.1, 2.4, 1.8, 4.3, 2.7]}
            {label: "twitter" data: [1.6, 0.4, 0.8, 2.4, 1.2]}
          ]
        }
      )
      {
        id
        chart
      }
    }
''')
chart = response['data']['CreateInsight']['chart']
response
Out[2]:
{'data': {'CreateInsight': {'id': '10',
   'chart': {'title': 'Social Media Usage',
    'type': 'line',
    'category_axis': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
    'series': [{'label': 'facebook', 'data': [2.1, 2.4, 1.8, 4.3, 2.7]},
     {'label': 'twitter', 'data': [1.6, 0.4, 0.8, 2.4, 1.2]}]}}}}
In [3]:
data = []
for series in chart['series']:
    data.append([series['label'], series['data']])
data
Out[3]:
[['facebook', [2.1, 2.4, 1.8, 4.3, 2.7]],
 ['twitter', [1.6, 0.4, 0.8, 2.4, 1.2]]]
In [4]:
stackedline_chart = pygal.StackedLine(fill=True)
stackedline_chart.title = "Hours spend on Social Media"
stackedline_chart.x_labels = chart['category_axis']
In [5]:
for label, data_points in data:
    stackedline_chart.add(label, data_points)
In [6]:
display(SVG(stackedline_chart.render(disable_xml_declaration=True)))
Hours spend on Social Media2233445566MondayTuesdayWednesdayThursdayFridayHours spend on Social Media2.112.515384615384615473.85635792778646Monday2.4168.9576923076923443.5973312401884Tuesday1.8325.4504.1153846153846Wednesday4.3481.84230769230766251.95682888540028Thursday2.7638.2846153846153413.3383045525902Friday3.7 (+1.6)12.515384615384615312.4748822605965Monday2.8 (+0.4)168.9576923076923403.2519623233909Tuesday2.6 (+0.8)325.4423.42464678178965Wednesday6.7 (+2.4)481.842307692307669.884615384615358Thursday3.9 (+1.2)638.2846153846153292.3021978021977Fridayfacebooktwitter