MathymaGraph Reference

Page Contents

Graph Methods

constructor

myGraph = new mathyma.Graph ( [windowWidth [, windowHeight ]] )
myGraph
the new instance of a mathyma.Graph object created.
(number) windowWidth
the width of the applet window in pixels (default is 360)
(number) windowHeight
the height of the applet window in pixels (default is 360)

addLabel

myGraph.addLabel ( text , x-coord , y-coord )

This method adds a label to the latest drawing to be drawn on the graph. See the mathyma.GraphDrawing object addLabel( ) method below for an explanation of the parameters.

addShade

myGraph.addShade ( from-x , to-x )

This method adds shade to the latest function or step function to be drawn on the graph. See the mathyma.GraphDrawing addShade( ) method below for an explanation of the parameters.

drawArrow

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawArrow ( from-x , from-y , to-x , to-y [, head] )
(number) from-x and (number) from-y
The coordinates of the starting point of the line.
(number) to-x and (number) to-y
The coordinates of the end point of the line.
(number) head
The relative size of the head of the arrow. Default is 1 (i.e. the length of the arrow head is the same as the length of the arrow).

drawCurve

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawCurve ( x-function , y-function [, from-t [, to-t [, points ]]] )
(string) x-function
a formula for x in terms of the variable t. See function formulae below.
(string) y-function
a formula for y in terms of the variable t. See function formulae below.
(number) from-t and (number) to-t
define the range of the variable t used in the x- and y- functions. Default is -1 to +1.
(number) points
the number of points (excluding the start point) in the t-range, defining the "resolution" of the curve. Default as defined by setPoints( ) method.

drawFunction

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawFunction ( function [, from-x [, to-x [, points ]]] )
(string) function
a formula for y in terms of the variable x. See function formulae below.
(number) from-x and (number) to-x
define the range of the variable x used in the function. Default as defined by setXrange( ) method.
(number) points
the number of points (excluding the start point) in the x-range, defining the "resolution" of the function. Default as defined by setPoints( ) method.

drawLine

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawLine ( from-x , from-y , to-x , to-y )
(number) from-x and (number) from-y
The coordinates of the starting point of the line.
(number) to-x and (number) to-y
The coordinates of the end point of the line.

drawPin

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawPin ( coords )
(string) coords
the y- and y-coordinates of the points of the pins in the format "x1 , y1 , x2 , y2 , ... "

pins are drawn down to the x-axis (for positive points) and up to the x-axis (for negative points).

drawPolygon

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawPolygon ( coords [, isClosed ] )
(string) coords
the y- and y-coordinates of the polygon in the format "x1 , y1 , x2 , y2 , ... "
(boolean) isClosed
set to true or false to indicate whether it is a closed polygon or not

drawScatter

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawScatter ( coords )
(string) coords
the y- and y-coordinates of the points to be drawn in the format "x1 , y1 , x2 , y2 , ... "

drawStep

[(mathyma.GraphDrawing object) myDrawing = ] myGraph.drawStep ( function, stepWidth, stepType [, from-x [, to-x ]] )
(string) function
a formula for y in terms of the variable x. See function formulae below.
(number) stepWidth
the width of the steps (in x-axes units).
(string) stepType
can take the value "on", "below" or "above" to indicate the position of the steps relative to the defining function. Any other value will be interpreted as "on".
(number) from-x and (number) to-x
define the range of the variable x used in the function. Default as defined by setXrange( ) method.

drawText

myGraph.drawText ( text, x-coord , y-coord )
(string) text
the text to be displayed on the graph.
(number) x-coord and (number) y-coord
define the (bottom left) position of the text on the graph.

print

myGraph.print ( [window] )
(window object) window
The window in which the graph is to be displayed. If this is not specified the graph will be displayed on the current web page.

See w3schools.com window object and window.open() method for how to set up a window.

printInWindow

myGraph.printInWindow ( [text1] , [text2] )
(text) text1
First line of text printed below graph.
(text) text2
Second line of text printed below graph.

setColours

myGraph.setColours ( colours )
(string) colours
the sequence of coulours to be used in turn for the drawings on the graph, in the format: "colour1, colour2, ... " where the colours can be "red", "orange", "yellow", "green", "cyan", "blue", "violet", "grey", "black", or "white". (The colour sequence is not case sensitive.)

setPoints

myGraph.setPoints ( points )
(number) points
the number of points (excluding the start point) in the x-range (for functions and steps) or t-range (for curves), defining the "resolution" of the drawing. Default 100.

setWindow

myGraph.setWindow ( windowWidth , windowHeight )
(number) windowWidth
the width of the applet window in pixels (default is 360)
(number) windowHeight
the height of the applet window in pixels (default is 360)

setXgrid

myGraph.setXgrid ( gridWidth )
(number) gridWidth
the width of the x-grid (in x-axis units). If this is not set, MathymaGraph chooses the most appropriate number.

setXrange

myGraph.setXrange ( from-x , to-x )
(number) from-x and (number) to-x
define the range of the variable x for the graph. If this is not set MathymaGraph sets the range to accomodate the minimum and maximum x in the set of drawings.

setXtitle

myGraph.setXtitle ( text )
(string) text
the text to be used as the title for the x-axis (horizontal).

setYstretch

myGraph.setYstretch( y-stretch )
(number) y-stretch
the ratio of the y-axis to the x-axis. For example a y-stretch of 4 means that a y-axis unit will be 4 times as large as an x-axis unit

setYtitle

myGraph.setYtitle ( text )
(string) text
the text to be used as the title for the y-axis (vertical).

GraphDrawing Methods

There is no free-standing constructor for this class of object. They are created by the drawing methods of mathyma.Graph objects as documented above.

addLabel

myDrawing.addLabel ( text, x-coord , y-coord )
(string) text
the label of the drawing to be displayed on the graph.
(number) x-coord and (number) y-coord
define the (bottom left) position of the label on the graph.

Only one label can be displayed per drawing (mathyma.GraphDrawing object), if several labels are added to the same drawing, only the last to be added will be printed.

addShade

myDrawing.addShade ( from-x , to-x )
(number) from-x and (number) to-x
define the values of x for which the area between the function graph or step function and the x-axis is to be shaded.

Several areas of shade can be added to the same function or step. Using addShade with any other type of drawing will have no effect.

Function Formulae

drawFunction, drawStep, and drawCurve all have function formulae as some of their arguments. A function formula is a string which can contain the following elements:

  • The character "x" (in drawFunction and drawStep) or "t" (in drawCurve)to represent the variable
  • Numerical characters 0-9
  • The mathematical symbols "+" (plus), "-" (minus), "*" (multiply), "/" (divide)
  • Brackets "(" and ")".
  • Any of the following (JavaScript) functions (followed by arguments in brackets):
    • abs (absolute value)
    • sin, cos, tan (trigonometrical functions - argument in radians)
    • asin, acos, atan, atan2 (inverse trigonometrical functions - return value in radians)
    • exp, log (exponential and natural logarithm)
    • ceil (least integer greater than argument )
    • floor (greatest integer less than argument )
    • round (rounds argument to nearest integer)
    • max, min (maximum or minimum (respectively) of two arguments )
    • pow (raises first argument to the power of the second)
    • sqrt (the positive square root of the argument - which must be positive)
    • random (a random number between 0 and 1)
  • The constant "PI " (the space at the end is mandatory).
  • Blanks (white space) between any of the above elements - though this is not necessary.