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