essentially, I have this boilerplate code in my html file, which works fine.
<div id="finvel" style="width:600px;height:250px;">
<script>
FINVEL = document.getElementById('finvel');
Plotly.plot( FINVEL, [{
x: [0,1,2,3,4,5,6],
y: [2,4,3,2,11,12,14]}], {
margin: { t: 0 } } );
</script>
however, I want to pass values into x: and y: from my function in my .js file shown below.
function calculateFinalVelocity()
{
var initialvelocity = document.getElementById("initialvelocity_final1").value;
var acceleration = document.getElementById("acceleration_final1").value;
var time = document.getElementById("time_final1").value;
var finalvelocity = Number(initialvelocity) + (Number(acceleration) * Number(Math.abs(time)));
document.getElementById("answer_final1").innerHTML = 'The Final Velocity is found to be: ' + finalvelocity + ' m/s';
var i = 0;
var num_velocity_array = [];
var time_array = [];
let number = i + 0.25;
for (var i = initial_time; i <= time; number)
{
num_velocity = Number(initialvelocity) + (Number(acceleration) * Number(initial_time));
time_array.push(initial_time);
num_velocity_array.push(num_velocity);
}
}
for x: I would like to pass the time_array variable, and for y: I would like to pass the num_velocity_array variable so I assumed the following would work:
<script>
FINVEL = document.getElementById('finvel');
Plotly.plot( FINVEL, [{
x: time_array,
y: num_velocity_array}], {
margin: { t: 0 } } );
</script>
but this does not work…
I’ve been working on this for days… any help would be appreciated!
Evan