Sample Calulcator Plotting 2

by Shawn Lackey

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
Slope Interept Calculator<br/><br>
y = mx + b<br/><br/>

     Input m <input type="text" id="m" size="5" /><br/>
     Input b <input type="text" id="b" size="5" /><br/>
     X Min<input type="text" id="xmin" value="1" size="5"/>
     X Max<input type="text" id="xmax" value="10" size="5" />
<br/><br/>
    
<input type="button" value="Calculate" id="calculate" />
<input type="button" value="Plot" id="plot" />

<br/><br/>
<p id="output"> </p>  

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

JavaScript

// Global variables
var m = 0;
var b = 0;
var n = 0;
var x = new Array();
var y = new Array(); 
var v = new Array();

function calculateY(m, b, x) {
    return m * x + b;
}

function calculate() {
    m = Number($('#m').val());
    b = Number($('#b').val());
    var xmin = Number($('#xmin').val());
    var xmax = Number($('#xmax').val());
    var xt = 0;
    
    
    var i = 0;
    for (xt = xmin; xt <= xmax; xt++) {
        x[i] = xt;
        y[i] = calculateY(m, b, xt);
        v[i] = [x[i], y[i]];
        i++;
    }
    n = i - 1;
    
}

function displayValues()
{
   var s = "";
    
    s = "Y = " + m + " x + ";
    s+= b + "<br/><br/>";
    
    for (var i = 0; i <= n; i++)
    {
        s += " X = " + x[i] + " Y = " + y[i] + "<br/>";       
    }
    
    output.innerHTML = s;
}

function plotValues()
{
   calculate();
   chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'line',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'Quadratic Equation',
                x: -20 //center
            },
            xAxis: {
                title: {
                    text: 'X'
                }
            },
            yAxis: {
                title: {
                    text: 'Y'
                }   
            }, 
       
       plotOptions: {
                scatter: {
                    marker: {
                        radius: 5,
                        states: {
                            hover: {
                                enabled: true,
                                lineColor: 'rgb(100,100,100)'
                            }
                        }
                    },
                    states: {
                        hover: {
                            marker: {
                                enabled: false
                            }
                        }
                    }
           ...