From f9a5a7949e90fb07068b16a7e8ec8812d1bba5aa Mon Sep 17 00:00:00 2001 From: Walker Waylon Scott Date: Sun, 21 May 2017 10:48:57 -0500 Subject: [PATCH] generalized layouts --- app/static/chartist.js | 38 ++++++++++++++++++++++++ app/templates/chartist.html | 19 ++++++++++++ app/templates/chartist.js | 38 ++++++++++++++++++++++++ app/templates/chartist_head_scripts.html | 4 +++ 4 files changed, 99 insertions(+) create mode 100644 app/static/chartist.js create mode 100644 app/templates/chartist.html create mode 100644 app/templates/chartist.js create mode 100644 app/templates/chartist_head_scripts.html diff --git a/app/static/chartist.js b/app/static/chartist.js new file mode 100644 index 0000000..8eb9b85 --- /dev/null +++ b/app/static/chartist.js @@ -0,0 +1,38 @@ +var mychart; + +var nation = $("#nation option:selected").text() +var getData = $.get('/data/'.concat(nation)); + +getData.done(function(results){ + + var data = { + labels: results.labels, + series: [ + results.results + ] + }; + + mychart = new Chartist.Line('.ct-chart', data); + +}) + +function updateChart(){ + var nation = $("#nation option:selected").text() + + var updatedData = $.get('/data/'.concat(nation)); + + updatedData.done(function(results){ + var data = { + labels: results.labels, + series: [ + results.results + ] + }; + + mychart.update(data) + }); + +} + +$('#update').on('click', updateChart) +$('#nation').on('change', updateChart) \ No newline at end of file diff --git a/app/templates/chartist.html b/app/templates/chartist.html new file mode 100644 index 0000000..534098d --- /dev/null +++ b/app/templates/chartist.html @@ -0,0 +1,19 @@ +{% from "_render_field.html" import render_field %} + +

Population by Nation


+data from +data.world +

+Created with Flask and chartist.js + + + + +
+ World Population +{{ render_field(form.nation) }} + + +
+ +
\ No newline at end of file diff --git a/app/templates/chartist.js b/app/templates/chartist.js new file mode 100644 index 0000000..8eb9b85 --- /dev/null +++ b/app/templates/chartist.js @@ -0,0 +1,38 @@ +var mychart; + +var nation = $("#nation option:selected").text() +var getData = $.get('/data/'.concat(nation)); + +getData.done(function(results){ + + var data = { + labels: results.labels, + series: [ + results.results + ] + }; + + mychart = new Chartist.Line('.ct-chart', data); + +}) + +function updateChart(){ + var nation = $("#nation option:selected").text() + + var updatedData = $.get('/data/'.concat(nation)); + + updatedData.done(function(results){ + var data = { + labels: results.labels, + series: [ + results.results + ] + }; + + mychart.update(data) + }); + +} + +$('#update').on('click', updateChart) +$('#nation').on('change', updateChart) \ No newline at end of file diff --git a/app/templates/chartist_head_scripts.html b/app/templates/chartist_head_scripts.html new file mode 100644 index 0000000..c00f378 --- /dev/null +++ b/app/templates/chartist_head_scripts.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file