Assignment4

by zazagalaxy

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 350px; height: 400px; margin: 0 auto"></div>

<div id="output">

</div>

<form name="calculator" action="javascript:start();">
Initial Quantity in mg<input id="quantity" type="decimal" name="quantity">
<br/>
<br/>
Elapsed time in years <input id="time" type="decimal" name="time">
<br/>
<br/>
<select id="isotope" type="text" name="isotope" value="isotope">
<option value="0.0017">Sodium-24 - Half-life: 15 hours</option>
<option value="0.022">Iodine-131 - Half-life: 8.07 days</option>

<option value="5.26">Cobalt-60 - Half-life: 5.26 years</option>
<option value="1600">Radium-226 - Half-life: 1,600 years</option>

</select>
<input type="submit" value="Calculate Decay">
</form>

JavaScript

function plotdata(ao, t, th) {

var chart;
var data = calculate(ao, t, th);

chart = new Highcharts.Chart('container', {
           chart: {
                renderTo: 'container',
                type: 'line',
 
            },
            title: {
                text: 'Radioactive Decay'
            },
            xAxis: {
                title: {
                    text: 'Years',
                    min: 0
                }
            },
            yAxis: {
                title: {
                    text: 'Quantity',
                    min: 0
                }   
            }, 
       
       plotOptions: {
                scatter: {
                    marker: {
                        radius: 5,
                        states: {
                            hover: {
                                enabled: true,
                                lineColor: 'rgb(100,100,100)'
                            }
                        }
                    },
                    states: {
                        hover: {
                            marker: {
                                enabled: false
                            }
                        }
                    }
                }
            },
       tooltip: {
    crosshairs: [true, true]
},
       series: [{
                name: 'Radioactive Decay',
                color: 'rgba(223, 83, 83, .5)',
                data: data
       }]
   });
 }
function rdecay(ao, t, th) {
	let e = Math.E;
  let l = -0.693;
  return (100 * e ** ((l * t)/th));
}
   
   
function calculate(ao, t, th) {
  let values = [];
  let years = [];
  for (let time = 0; time <= t; time += parseInt(t/10)) {
  	values.push([time,rdecay(ao, time, th)])
  }
  return values;
}

function start() {
let ao =	parseFloat(document.forms["calculator"]["quantity"].value);
let t =	parseFloat(document.forms["calculator"]["time"].value);
let th =	document.forms["calculator"]["isotope"].value;
plotdata(ao, t, th)
}



plotdata(100,...