-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 Make call to backend to get array of random integers and graph thi…
…s on a bar chart on the frontend
- Loading branch information
Showing
3 changed files
with
58 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,11 +47,9 @@ <h1>applepy</h1> | |
|
||
</div> | ||
|
||
</div> | ||
|
||
<!-- Optional JavaScript --> | ||
<!-- jQuery first, then Popper.js, then Bootstrap JS --> | ||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> | ||
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> | ||
<!-- Custom javascript --> | ||
|