My ORIGINAL POST:
I've put together a fiddle to showcase how my data is sourced from JSON and displayed in a ColumnChart.
https://jsfiddle.net/w4dokdt9/3/
This is an example of how my JSON data is structured:
[{"lPlusScoreID":1,"jan":60.03,"feb":43.57,"mar":48.55},
{"lPlusScoreID":2, "jan":89.42,"feb":85.71,"mar":90.46},
{"lPlusScoreID":3,"jan":86.22,"feb":90.61,"mar":89.53}]
The resulting column chart looks like this: Link to Chart Image
My objective is to have months along the x-axis and products as columns/bars.
How can I achieve this? I'd prefer using a Google Visualization chart, method, or configuration option. If data transformation through coding is necessary, I'm open to it, but I'm new to development.
Thank you for any assistance!
Here's my EDITED POST:
I've managed to implement the code below.
- Created
dataArray_input
with predefined months and then populated it with data from the original JSON. Utilized the
transposeArray()
function to transposedataArray_input
intodataArray_trans
.function transposeArray(a) { return Object.keys(a[0]).map(function (c) { return a.map(function (r) { return r[c]; }); }); }
Appended
dataArray_trans
to the finaldataArray_output
using theappendArray()
function, which is then used by the Google API.function appendArray(a, b) { for (var i = 0; i < a.length; i++) { b.push(a[i]); } }
Below is the final code snippet.
I'd appreciate feedback to ensure I'm progressing in the right direction. I'm new to this field.
Special thanks to @WhiteHat for the prompt and effective solution.
Code snippet: