{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pygal\n",
"from IPython.display import SVG, display\n",
"from memair import Memair\n",
"# Use Otto the sandbox user's access token or create your own at https://memair.com/temporary_access_token\n",
"access_token = '0000000000000000000000000000000000000000000000000000000000000000'\n",
"\n",
"user = Memair(access_token)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'data': {'CreateInsight': {'id': '10',\n",
" 'chart': {'title': 'Social Media Usage',\n",
" 'type': 'line',\n",
" 'category_axis': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],\n",
" 'series': [{'label': 'facebook', 'data': [2.1, 2.4, 1.8, 4.3, 2.7]},\n",
" {'label': 'twitter', 'data': [1.6, 0.4, 0.8, 2.4, 1.2]}]}}}}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"response = user.query('''\n",
" mutation { \n",
" CreateInsight(\n",
" chart: {\n",
" title: \"Social Media Usage\"\n",
" type: line\n",
" category_axis: [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\"]\n",
" series: [\n",
" {label: \"facebook\" data: [2.1, 2.4, 1.8, 4.3, 2.7]}\n",
" {label: \"twitter\" data: [1.6, 0.4, 0.8, 2.4, 1.2]}\n",
" ]\n",
" }\n",
" )\n",
" {\n",
" id\n",
" chart\n",
" }\n",
" }\n",
"''')\n",
"chart = response['data']['CreateInsight']['chart']\n",
"response"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[['facebook', [2.1, 2.4, 1.8, 4.3, 2.7]],\n",
" ['twitter', [1.6, 0.4, 0.8, 2.4, 1.2]]]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = []\n",
"for series in chart['series']:\n",
" data.append([series['label'], series['data']])\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"stackedline_chart = pygal.StackedLine(fill=True)\n",
"stackedline_chart.title = \"Hours spend on Social Media\"\n",
"stackedline_chart.x_labels = chart['category_axis']"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"for label, data_points in data:\n",
" stackedline_chart.add(label, data_points)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(SVG(stackedline_chart.render(disable_xml_declaration=True)))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}