score:1
Accepted answer
if you replace measurement
with data.series
and get rid of the hasownproperty(measurement)
thing, you are almost there. the only thing you need is a way to keep the transformation from a list of {date, value} objects to a pair of list of dates and value for each serie.
var series = {};
// this loop is looping across all the series.
// x will have all the series names (heights, lengths, etc.).
for (var x in data.series) {
var dates = [];
var values = [];
// loop across all the measurements for every serie.
for (var i = 0; i < data.series[x].length; i++) {
var obj = data.series[x][i];
// assuming that all the different series (heights, lengths, etc.) have the same two date, value attributes.
dates.push(obj.date);
values.push(obj.value);
}
// keep the list of dates and values by serie name.
series[x] = {
dates: dates,
values: values
};
}
series
will contain this:
{
heights: {
dates: [
'2014-10-01',
'2014-10-01',
'2014-10-01'
],
values: [
22,
53,
57
]
},
lengths: {
dates: [
'2014-10-01',
'2014-10-01'
],
values: [
54,
33
]
}
}
so you can use them like this:
console.log(series);
console.log(series.heights);
console.log(series.heights.dates);
console.log(series.heights.values);
console.log(series.lengths);
console.log(series.lengths.dates);
console.log(series.lengths.values);
Source: stackoverflow.com
Related Query
- Looping through json array properties
- Can't load multiple charts onto a page when looping through dummy array
- Live Update Callback -> afterTitle with Array via JSON file
- How to map json array to two different array for chart
- Passing an Array from a Flask view to the javascript code of another view
- Load data from a JSON object into an array
- How to create a custom tooltip for chartJS graph with data in JSON array in JavaScript?
- Converting JSON data into Chart.js array from strings
- Passing JSON data from PHP array into ChartJS
- How to write better code in es6 for formatting an object with array values
- How to properly unpack data from PHP array encoded as JSON from a JavaScript file
- is it possible to sum up the properties of an array of objects and to filter it according to another property?
- Chart.js - Multiple JSON data object array [{x: Date, y: count}....] representing each dataset of the chart
- Loop through array for chart.js input
- Javascript How to give color using conditional statement based on json array state value
- Loop through array of objects in Node
- Iterating through array in Chart.js data field
- Trying to access key in JSON array
- Php/ajax return JSON in same form as javascript array
- Looping through afterDraw in ChartJS
- Parsing an unnamed JSON array into React component
- Get Array with json without _chartjs: {…}, push: ƒ, pop: ƒ, shift: ƒ, splice: ƒ, …]
- how can i grab a property from an array of JSON objects to use the values of that property as a labels in my chart?
- How to run Chart.js samples using source code
- How to bind json array data to chart.js with same canvas id?
- Dynamically Creating Json Array Javascript
- Looping variables or array
- Convert a JSON file to an array in javascript to visualize the data in ChartsJS
- How to convert Json to Array In javascript for chart.js
- How to populate a charts.js pie chart using json array
More Query from same tag
- Rendering charts using local Chart.js in overriding Django templates
- Chart.js (line chart) tooltip duration/delay
- How to add overlay color to chart.js pie chart segment?
- Hide all scale labels in chartjs
- Chart.js Auto Fit Failing
- ChartJS TypeError: document.getElementById(...).getContext is not a function
- Chart.js load new data
- Chart.js not stretching width as per data
- Add buffer to Y axis with chart js
- ChartJS - Highlight Weekends and Lowest and Highest Values
- Chart JS - Remember hidden label state after page refresh
- End x-axis on last data point (scatter plot) for x,y numeric values
- Non-static values for chart using CanvasJS?
- Rendering Chart.js Bubble Chart Using Array Data
- How to set data values as labels in Chart.js with a Radar Chart
- Chart.js Chart displays but no data
- How to change default label of each bubble in bubble chart using chartjs-plugin-datalabels
- chart.js Line chart doesn't display line past a certain point in the chart
- How to specify hover color angular-chart.js
- Charts.js graph not scaling to canvas size
- Charts.js - Colors for stacked bar on multi-series line/bar chart are not working
- Change dot size individually Scatter Chart -- ChartJS
- Render labels only when the data is available for a particular label
- Draw a single frame in Chart.js
- Chartjs is disappearing in Ionic tabs when keyboard dismiss
- Plotting objects in Chart.js
- How to add left padding for my charts done in ChartJs and my Google Map so it is not glued to the limit of the page on the left
- chart.js adjust height in mobile view
- Unable to create Stacked Grouped Bar Chart with chart.js / react-chartjs-2 in React
- How to get x-axis value in chart as string?