Fork me on GitHub
jsGraph

Graph initialization

Initializing a new graph is o done through the Graph constructor. The first parameter is a reference the wrapping element that you must have already created beforehand.

var dom = document.getElementById("someDiv");
var g = new Graph( dom );

// or
var g = new Graph( "someDiv" );

However the wrapper does not necessarily need to be embedded in the document. The following works just as fine :

var dom = document.createElement("div");
var g = new Graph( dom );

By default the graph will fit to the size of the wrapper. If no size is defined the graph will take a size by default (i.e., the width of the div which is 100% of its parent, and a browser-defined default svg height, 150px). If the wrapper dimension has changed, you can notify the graph by calling

g.resize( w, h ); // w and h must be numbers
Param Description
domWrapper The wrapper element (DOM object). Usually an empty div, but not necessarily. The element doesn't need to be included in the document
options The graph options. An object of key/values that define the general behaviour of the graph.
axis An object defining which axis to use for the graph. All of those options are available through the API (although it's a bit more tedious). See the section of Defining Axis for a detailed description. Note: the parameter options becomes non-optional if you want to specify axis
callback The callback is triggered when the graph is loaded. This feature is mostly used for development purposes, where series and plugins are loaded asynchronously. In such case the callback will be fired after all the required javascript files have been loaded.