//Preliminaries to do line charts
google.load('visualization', '1', {packages: ['corechart', 'line']});
google.setOnLoadCallback(initChart);
// Variables in the global environment
var chart, data;
var options = {
hAxis: {title: 'X'},
vAxis: {title: 'Function Y(X)'},
legend:{position:'none'}
};
// Compute the table of polynomial value using coefficients specified in the form
function getTable() {
var a = Number(document.getElementById('a').value);
var b = Number(document.getElementById('b').value);
var c = Number(document.getElementById('c').value);
var d = Number(document.getElementById('d').value);
var min = Number(document.getElementById('min').value);
var max = Number(document.getElementById('max').value);
var table = [ ];
for (var x=min ; x<=max ; x++) {
table.push([x, a*Math.pow(x, 3) + b*Math.pow(x, 2) + c*Math.pow(x,1) + d*Math.pow(x,0)]);
}
return(table);
}
// Initialise the chart
function initChart() {
// Create the chart and data instances
chart = new google.visualization.LineChart(document.getElementById('chart'));
data = new google.visualization.DataTable();
// Add columns to the data
data.addColumn('number', 'X');
data.addColumn('number', 'Y(X)');
// Add rows to the data from some source
data.addRows(getTable());
// Draw the chart with options
chart.draw(data, options);
}
// Update the chart values for y(x) but keep the same x values
function updateChart() {
var table = getTable();
for (var r=0; r< table.length ; r++) {
var row = table[r];
data.setValue(r, 1, row[1]);
}
chart.draw(data, options);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.