Examples Involving a User Interface

There are several ways the user might be involved in creating a plot.


Example i1: prompt for f(x) or data

This is the very simplest use of divgraph.js.

Example i1

prompt for f(x) or data

Execute JavaScript
View the code

 

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


Example i2: prompt for x-range

In this case, the function is given, but the x-range values are missing.

Example i2

prompt for x-range

Execute JavaScript
View the code

 

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


Example i3: entering x,y data in a form's textarea

This example shows how a user's own x,y data can be plotted.

Execute JavaScript

View the code


Example i3a: entering x,y data in a form's textarea

This example of a general plotter for titration data is from the Principal Species in Solution page. Go ahead and change the data and click on "Execute JavaScript." Lots of parameters are defined, because it is a very specific type of plot that we want.

Execute JavaScript

View the code


Example i4: entering colors and labels in textboxes

Colors and labels can be introduced as textbox data. A vertical bar separates the "alt" label, which pops up when the mouse moves over the point, from the displayed label, which is displayed directly on the graph. This displayed label may be any valid HTML code, including forms, buttons, links, and images.

Example i4

entering colors and labels in textboxes

Execute JavaScript
View the code

 


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


Example i5: form entry of parameters with indication of completion

This example shows how the user might select various plotting options based on data presented. At the end of the plotting, the Info.whendone parameter causes the function check() to be run. Can you figure out how to plot the data in order to get a straight line?

time(sec) [NO2]
   0      0.0100
  50      0.0079
 100      0.0065
 200      0.0048
 300      0.0038

Vertical Axis:
Horizontal Axis:
Do you want to add a curve
through the points? yes no
Do you want a trend line? yes no

Execute JavaScript

View the code


Example i6: data plotter with title-based feedback

This example shows how the user might be able to enter their own data along with selecting various plotting options based on data presented. These data are kinetics data similar to what might be obtained using the Mechanism-Based Kinetics Simulator. At the end of the plotting, the Info.title parameter includes a link to opener.check(), which allows after-plotting feedback directed by the user. These are data showing the effect of temperature on the rate constant for a chemical reaction. Can you figure out how to plot the data in order to get a straight line?

,

Vertical Axis:
Horizontal Axis:
Do you want to add a curve
through the points? yes no
Do you want a trend line? yes no
data point color: size:
curve color:

Execute JavaScript

View the code


Example i7: animated histogram

This example shows how to draw a histogram with control buttons that the user can use to start and stop animation.

Execute JavaScript

View the code


Example i8: dynamic histogram spectrum with mouse-action feedback

This example shows how a histogram can be used to display an NMR spectrum on the fly based on data in a textarea. Mouse-down events on the graph are trapped. The only really complex aspect of the code is the getnmrdata() function, which reads the textarea information and translates it into a Data[] array representing the NMR spectrum.

Enter 1H NMR data in the form
"shift (ppm),integral,type,J values (Hz)

Spectrometer Frequency: MHz
Display from to ppm

Execute JavaScript

View the code

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.