Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19457 > unrolled thread
| Started by | shawnroller10@gmail.com |
|---|---|
| First post | 2013-04-24 20:15 -0700 |
| Last post | 2013-04-25 10:25 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.javascript
Formatting JSON document to Data Table shawnroller10@gmail.com - 2013-04-24 20:15 -0700
Re: Formatting JSON document to Data Table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-25 10:25 +0200
| From | shawnroller10@gmail.com |
|---|---|
| Date | 2013-04-24 20:15 -0700 |
| Subject | Formatting JSON document to Data Table |
| Message-ID | <d6020bd0-9540-4191-bcac-9b296866c8e1@googlegroups.com> |
I need some assistance in creating a data table from a JSON document. The data table format looks like this:
{
"cols": [
{"id":"","label":"Date","type":"date"},
{"id":"","label":"M01","type":"number"},
{"id":"","label":"M02","type":"number"},
{"id":"","label":"M03","type":"number"}
],
"rows": [
{"c":[{"v":"2013-04-21"},{"v":101},{"v":153},{"v":189}]},
{"c":[{"v":"2013-04-22"},{"v":109},{"v":145},{"v":175}]},
{"c":[{"v":"2013-04-23"},{"v":95},{"v":165},{"v":201}]},
{"c":[{"v":"2013-04-24"},{"v":114},{"v":147},{"v":193}]}
]
}
The cols are essentially columns of a table and each of the items in the rows array are the values of the columns (ex. {"v":value})
A sample of my data, returned from a query via an Ajax command, might look like this:
{{[{
"_index" : "kpi",
"_type" : "routes_by_lane",
"_id" : "7_2ezuYQTHyr2XG8x-TnJA",
"_score" : null, "_source" : {"warehouse_id":"107","date":"2013-04-21","lane":"M01","routes":101}
"sort" : [ 1366675200000 ]
}, {
"_index" : "kpi",
"_type" : "routes_by_lane",
"_id" : "Xs03HMA8QiCoYmDuyjhBxA",
"_score" : null, "_source" : {"warehouse_id":"107","date":"2013-04-21","lane":"M02","routes":153}
"sort" : [ 1366675200000 ]
}, {
"_index" : "kpi",
"_type" : "routes_by_lane",
"_id" : "s_2ubycJT4i9qWT9u46Nhw",
"_score" : null, "_source" : {"warehouse_id":"107","date":"2013-04-22","lane":"M01","routes":109}
"sort" : [ 1366675200000 ]
} ]
}
}...
The entire query result would actually include some headers and also would include a separate document for each lane (M01, M02...) and for each date. So for the sample data at the top, that would actually be pulled from 12 sub-documents like those immediately above.
Can someone assist in recommending a way to format this data? I'm currently using an object, var ldata = {} but I need to put the data into the ldata.cols and ldata.rows. The major obstacle is to get the proper number (routes) for each lane and for each day.
Any help would be greatly appreciated!
[toc] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-04-25 10:25 +0200 |
| Message-ID | <24865100.GETcoMUama@PointedEars.de> |
| In reply to | #19457 |
shawnroller10@gmail.com wrote:
> I need some assistance in creating a data table from a JSON document.
Thank you for _not_ saying (falsely) “JSON object”. I am not sure if
“document” is the correct term either, though.
> The data table format looks like this:
>
> {
> […]
> "rows": [
> {"c":[{"v":"2013-04-21"},{"v":101},{"v":153},{"v":189}]},
> {"c":[{"v":"2013-04-22"},{"v":109},{"v":145},{"v":175}]},
> {"c":[{"v":"2013-04-23"},{"v":95},{"v":165},{"v":201}]},
> {"c":[{"v":"2013-04-24"},{"v":114},{"v":147},{"v":193}]}
> ]
> }
>
> The cols are essentially columns of a table and each of the items in the
> rows array are the values of the columns (ex. {"v":value})
>
> A sample of my data, returned from a query via an Ajax command, might look
> like this:
>
> {{[{
> […]
> {"warehouse_id":"107","date":"2013-04-21","lane":"M01","routes":101}
> "sort" : [ 1366675200000 ]
> }, {
> […]
> {"warehouse_id":"107","date":"2013-04-21","lane":"M02","routes":153}
> "sort" : [ 1366675200000 ]
> }, {
> […]
> {"warehouse_id":"107","date":"2013-04-22","lane":"M01","routes":109}
> "sort" : [ 1366675200000 ]
> } ]
> }
> }...
>
> […]
> Can someone assist in recommending a way to format this data? I'm
> currently using an object, var ldata = {} but I need to put the data into
> the ldata.cols and ldata.rows. The major obstacle is to get the proper
> number (routes) for each lane and for each day.
I do not see the “major obstacle”. What have you tried and how did it fail?
And get a real name, please.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web