Triggering a javascript graph when a calculate button for an ROI Calculator is clicked
<p>I have an ROI calculator that generates some dynamic values that I want to input into a js graph that was added to the web page. The dynamic values are within the "var bar = new RGraph.bar" section of the function. As of now it loads those variables when the window loads. I'm trying to find the right code to run this script when the calculate button is clicked on the calculator on the same page. The code for the graph is below followed by the code for the calculate button. Thanks</p>

<p>//Graph//</p>

<pre><code>&lt;div id="roiGraph"&gt;
        &lt;h1&gt;Lifetime Cost Comparison&lt;/h1&gt;

        &lt;canvas id="cvs" width="260" height="200" align="center"&gt;[No canvas support]&lt;/canvas&gt;

        &lt;script&gt;
            window.onload = function ()
            {
                var bar = new RGraph.Bar('cvs', [[&lt;%= TraditionalMaintenanceCost %&gt;,&lt;%= TraditionalElectricityCost %&gt;, &lt;%= TraditionalCost %&gt;],[&lt;%= LedMaintenanceCost %&gt;,&lt;%= LedElectricityCost %&gt;,&lt;%= LedCost %&gt;]])
                bar.Set('grouping', 'stacked');
                bar.Set('labels', ['Existing','MaxLite']);
                bar.Set('labels.above', true);
                bar.Set('labels.above.decimals', 2);
                bar.Set('linewidth', 2);
                bar.Set('strokestyle', 'white');
                bar.Set('colors', ['66cc66','#cc3333','#286b8d']);
                bar.Set('hmargin', 10);
                bar.Set('gutter.left', 35);
                bar.Set('background.grid.vlines', false);
                bar.Set('background.grid.border', false);
                bar.Set('axis.color', '#ccc');
                bar.Set('noyaxis', true);


                bar.ondraw = function (obj)
                {
                    for (var i=0; i&lt;obj.coords.length; ++i) {
                        obj.context.fillStyle = 'white';
                        RGraph.Text(obj.context, 'Verdana', 10, obj.coords[i][0] + (obj.coords[i][2] / 2), obj.coords[i][1] + (obj.coords[i][3] / 2),obj.data_arr[i].toString(),'center', 'center', null,null,null,true);
                    }
                }

                bar.Draw();
            }
        &lt;/script&gt;

        &lt;div id="roiKeyTitles"&gt;
            Total Maintenence&lt;br&gt;
</code></pre>

<p>Total Electricity<br>
Total Initial Costs
            </p>

<pre><code>    &lt;/div&gt;
</code></pre>

<p>//Calculate button//
    </p>
