Examples Not Involving User Interaction

These examples don't allow the user to change the graph on their own.
They just plot the results of some sort of calculation or predefined data set.

Example 1

simple function of x with bounds set

Execute JavaScript
View the code

 

Example 2

f(x) with explicit tic information

Execute JavaScript
View the code

 

Example 2a

simple xy data with automatic tics

Execute JavaScript
View the code

 

Example 2b

simple xy data as a vertical-bar histogram

Execute JavaScript
View the code

 

Example 2c

simple xy data as a horizontal-bar histogram

Execute JavaScript
View the code

 

Example 2d

x,y data from an array

Execute JavaScript
View the code

 

Example 3a

simple xy data with a curve

Execute JavaScript
View the code

 

Example 3b

x,y data with a trend line

Execute JavaScript
View the code

 

Example 3c

x,y data transformed, with a trend line

Execute JavaScript
View the code

 

Example 4

multiple functions

Execute JavaScript
View the code

 

Example 4a

adding x,y data, reversing the axes

Execute JavaScript
View the code

 

Example 5

vertical histogram with reversed axis and styles

Execute JavaScript
View the code

 


Example 1: simple function of x with bounds set

Here we just specify the type of window we want, where to position the graph, and indicate the function and bounds.

Example 1

simple function of x with bounds set

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 2: f(x) with explicit tic information

In this example, we override the default tics with ones of our own.

Example 2

f(x) with explicit tic information

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 2a: simple xy data with automatic tics

This example illustrates the plotting of a simple set of x,y data.

Example 2a

simple xy data with automatic tics

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 2b: simple xy data as a vertical-bar histogram

This example illustrates the plotting of a simple set of x,y data as a vertical-bar histogram.

Example 2b

simple xy data as a vertical-bar histogram

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 2c: simple xy data as a horizontal-bar histogram

This example illustrates the plotting of a simple set of x,y data as a horizontal-bar histogram.

Example 2c

simple xy data as a horizontal-bar histogram

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 2d: x,y data from an array

An alternative method of entering xy data involves putting the data into an array. Each element of the array consists of an x,y pair followed, optionally, with a color and a "alternative" label (which shows up when the user moves the mouse over the point). Note that point "colors" are really just names of GIF files.

Example 2d

x,y data from an array

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 3a: simple xy data with a curve

divgraph.js will interpolate points to make a curve using a 3rd-order spline function. The paremeter that makes this happen is Info.docurve=true.

Example 3a

simple xy data with a curve

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 3b: x,y data with a trend line

Trend lines can be added to a graph with or without the equation listed. For programming purposes, the slope is returned as GR.L.m, and the intercept is returned as GR.L.b.

Example 3b

x,y data with a trend line

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 3c: x,y data transformed, with a trend line

One of the very powerful features of divgraph.js is its capability to automatically plot transformed data. In this case, the statement Info.datatransform="10/(5-y)^2 vs. ln(x)" does the job. These functions can be JavaScript math functions, or they can be any one of the following: sin(),cos(),tan(),log(),ln(),sqr(), or sqrt(). Standard notation for powers, a^b, is translated automatically into Math.pow(a,b).

Example 3c

x,y data transformed, with a trend line

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 4: multiple functions

More than one call to GRdrawgraph() can be made as long as the parameter Info.keepopen is set to true. Use Info.append=true to indicate that the second graph is being appended to the first.

Example 4

multiple functions

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 4a: adding x,y data, reversing the axes

This example illustrates how a second call to GRdrawgraph() can be made to add a second data set. In this case we reverse the x-axis by simply making Info.xmin greater than Info.xmax.

Example 4a

adding x,y data, reversing the axes

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.


Example 5: vertical histogram with reversed axis and styles

This example illustrates several features of divgraph.js, including the reversal of the x-axis by making Info.xmin greater than Info.xmax, using transparent points to annotate the graph, applying styles using Info.style, hiding the y-axis, and displaying data in the form of a histogram.

Example 5

vertical histogram with reversed axis and styles

Execute JavaScript
View the code

 

Change this code, then click on the "Execute JavaScript" link, to see the effect.

back to the list of examples


copyright 2001 Robert M. Hanson. All rights reserved. divgraph.js is freely distributable for noncomercial purposes, provided reference is made as "divgraph.js was developed at St. Olaf College by Robert M. Hanson (http://www.stolaf.edu/people/hansonr/divgraph)." Commercial licensing is available for specific purposes.