Rickshaw js: Why cant I do JSON.stringify & JSON.parse on the data object. Help appreciated.

edited January 2013 in Newbie Questions
<!doctype html>




var d = JSON.stringify([{
        color: 'steelblue',
        data: [ 
            { x: 0, y: 40 }, 
            { x: 1, y: 49 }, 
            { x: 2, y: 38 }, 
            { x: 3, y: 30 }, 
            { x: 4, y: 32 } ]
    }]);
    
    d = JSON.parse(d);

var graph = new Rickshaw.Graph( {
    element: document.querySelector("#chart"), 
    width: 285, 
    height: 180, 
    series: d
});

graph.render();

setInterval( function() {
	randm();
	// trick here. I want to convert the data object to string and use 
	// sessionStorage or localStorage and using JSON parser convert it back to object.
	d = JSON.stringify(d);
	d = JSON.parse(d);
	// end. If I do this my chart is not getting updated. Any guess ?
	console.log(d[0].data.length);
	graph.update();

}, 1000 );

function randm() {
	for (var i = 0; i < d.length; i++){
		d[i].data.push( {x: Math.floor((Math.random()*5)+1) , y: Math.floor((Math.random()*99)+1) });
	}
}

Comments

Sign In or Register to comment.