Time series

From JSXGraph Wiki
Revision as of 14:09, 17 June 2009 by A WASSERMANN (talk | contribs)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Simple style

JavaScript code

    brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, originX: 60, originY: 300, unitX: 10, unitY: 2});

    var inputString = document.getElementById('inputData').value;        // Read the data as string
    inputString = inputString.replace(/^\s+/, '').replace(/\s+$/, '');   // Remove leading and trailing whitespace
    var lines=inputString.split('\n');                                   // Split into lines
    var x = [];
    var y = [];
    var startDate;
    for (var i=0;i<lines.length;i++) { 
        var c = lines[i].split(' : ');
        var d = c[0].split('-');
        var v = parseFloat(c[1].replace(/,+/,'.'));                      // Change 126,5 to 126.5
        var date = new Date(d[0],d[1],d[2]);                             // Split the date into Year, Month, Day
        if (i==0) { startDate = new Date(d[0],d[1],d[2]); }              // Keep the first date in memory
        x[i] = (date.getTime()-startDate.getTime())/ ( 1000.0*60.0*60.0*24.0 );  // The x coordinate of a value is the number of days from the first entry
        y[i] = v;
        
    }
    var plot = brd.createElement('curve', [x,y], {strokeColor:'red'});            
</jsxgraph>

Time series - Google style