Skip to content

Instantly share code, notes, and snippets.



Created May 21, 2012
What would you like to do?
// This is the original object:
{"id":"202638c9041c87a2e01e1a320600074d","key":"202638c9041c87a2e01e1a320600074d","value":{"_id":"202638c9041c87a2e01e1a320600074d","_rev":"6-b28aa64f065a183c86c9d2097a1c81a7","company":"SAPA","project":"Replace wires system","contact":"Munetsi Chiunda","created":"","nextStep":"Roll-out prototype","value":"300000.00","state":{"0":"2012/3/15","1":"2012/4/19"},"type":"global"}},
{"id":"202638c9041c87a2e01e1a320600098c","key":"202638c9041c87a2e01e1a320600098c","value":{"_id":"202638c9041c87a2e01e1a320600098c","_rev":"7-7db0c0d4640bf7f070f4c34d7f746d2d","company":"ITWeb","project":"News diary","contact":"Jon Tullet","created":"2012/5/15","state":{"0":"2012/5/15","1":"2012/5/19"},"nextStep":"Get functional specficiation","value":"150000.00","type":"global"}}
// This is the object I want to create:
{"title": "SAPA", "data":"[[1331762400000, 0], [1334786400000, 1], [1337608923775, 1]},
{"title": "ITWeb", "data": [[1337032800000, 0], [1337378400000, 1], [1337608923782, 1]},
// This is the code I've been using
// Need to turn data object into a an object that flot can use/understand.
// Turn object into a multidimensional array
var dataArray = [];
var fullArray = [];
dataObj = new Object;
for (d in data) {
dataObj.title = data[d];
for (key in data[d].value.state) {
dataArray.push([new Date(data[d].value.state[key]).getTime(), key]);
var lastKey = key;
// Extend array so that line extends through to today
dataArray.push([new Date().getTime(), lastKey]);
// Push data into array with form [[date, value], [date, value]]
//empty array so old data doesn't contaminate the loop
dataArray = []; = fullArray;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.