diff --git a/app.py b/app.py index 605d42b..ebb5d7e 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ from flask import Flask from flask import render_template +from flask import jsonify app = Flask(__name__) from random import randint @@ -8,6 +9,9 @@ def index(): return render_template('index.html') -@app.route('/random') -def calculate(): - return str(randint(0,20)) +@app.route('/random/') +def random(size): + randList = [] + for x in range(0, int(size)): + randList.append(randint(0,20)) + return jsonify(randList) diff --git a/static/public/assets/js/backend.js b/static/public/assets/js/backend.js index 511f71a..86d569e 100644 --- a/static/public/assets/js/backend.js +++ b/static/public/assets/js/backend.js @@ -1,44 +1,57 @@ +function getChart(chartData) { + var ctx = document.getElementById('myChart').getContext('2d'); + var myChart = new Chart(ctx, { + type: 'bar', + data: { + labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], + datasets: [{ + label: '# of Votes', + data: chartData, + backgroundColor: [ + 'rgba(255, 99, 132, 0.2)', + 'rgba(54, 162, 235, 0.2)', + 'rgba(255, 206, 86, 0.2)', + 'rgba(75, 192, 192, 0.2)', + 'rgba(153, 102, 255, 0.2)', + 'rgba(255, 159, 64, 0.2)' + ], + borderColor: [ + 'rgba(255, 99, 132, 1)', + 'rgba(54, 162, 235, 1)', + 'rgba(255, 206, 86, 1)', + 'rgba(75, 192, 192, 1)', + 'rgba(153, 102, 255, 1)', + 'rgba(255, 159, 64, 1)' + ], + borderWidth: 1 + }] + }, + options: { + scales: { + yAxes: [{ + ticks: { + beginAtZero: true + } + }] + } + } + }); +} + +function generateChart() { + jQuery.get('/random/6', function(data, status) { + getChart(data) + }); +} + var app = new Vue({ el: '#app', data: { message: 'A basic n-body simulation program that aims to simulate many of the processes that occur in the early stages of the universe.' + }, + methods: { + graph: generateChart() } }) -var ctx = document.getElementById('myChart').getContext('2d'); -var myChart = new Chart(ctx, { - type: 'bar', - data: { - labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], - datasets: [{ - label: '# of Votes', - data: [12, 19, 3, 5, 2, 3], - backgroundColor: [ - 'rgba(255, 99, 132, 0.2)', - 'rgba(54, 162, 235, 0.2)', - 'rgba(255, 206, 86, 0.2)', - 'rgba(75, 192, 192, 0.2)', - 'rgba(153, 102, 255, 0.2)', - 'rgba(255, 159, 64, 0.2)' - ], - borderColor: [ - 'rgba(255, 99, 132, 1)', - 'rgba(54, 162, 235, 1)', - 'rgba(255, 206, 86, 1)', - 'rgba(75, 192, 192, 1)', - 'rgba(153, 102, 255, 1)', - 'rgba(255, 159, 64, 1)' - ], - borderWidth: 1 - }] - }, - options: { - scales: { - yAxes: [{ - ticks: { - beginAtZero: true - } - }] - } - } -}); +app.graph() diff --git a/templates/index.html b/templates/index.html index fdcb793..1908c72 100644 --- a/templates/index.html +++ b/templates/index.html @@ -47,11 +47,9 @@

applepy

- - - +