score:0
just make sure that arrayx and arrayy have the same lengths.
let arrayx = ["02/01/2014", "14/10/2014", "03/05/2014"];
let arrayy = [2, 10, 8];
let data = [];
for (let i in arrayx) {
data.push({
x: arrayx[i],
y: arrayy[i]
});
}
console.log('data: ' + json.stringify(data));
score:0
one way of merging it would by map over one of the arrays with referring to index in second:
const arrayx = ["02/01/2014", "14/10/2014", "03/05/2014"];
const arrayy = [2, 10, 8];
const data = arrayx.map((item, index) => ({
y: arrayy[index],
x: item,
}));
console.log(data);
it results:
[
{ y: 2, x: '02/01/2014' },
{ y: 10, x: '14/10/2014' },
{ y: 8, x: '03/05/2014' }
]
in the case of deeper nested structures, small modifications need to be applied to accommodate them. eg.
const arrayx = [ ["02/01/2014", "14/10/2014", "03/05/2014"] ];
const arrayy = [2, 10, 8];
const data = arrayx[0].map((item, index) => ({
.....
Source: stackoverflow.com
Related Query
- Javascript - Create objects to push in array
- How to create an array of objects dynamically in javascript for a pie chart
- How to push array multidimesional in javascript
- Passing an Array from a Flask view to the javascript code of another view
- How to Convert an Array of Objects into an Object of Associative Arrays in Javascript
- How to iterate over array elements inside objects in javascript
- How to add datas to chart js from javascript array itself?
- How to convert an array of strings to float in Javascript
- Is there a JavaScript Method/ Function to loop Objects via Keys into a array?
- Chart.js - How to push a collection of array into dataset
- Passing data to highcharts from javascript array or variable
- JavaScript critical error...Syntax Error (MVC 5) when passing array to Charts.js
- How to create a custom tooltip for chartJS graph with data in JSON array in JavaScript?
- Create New Array from Existing Array Values With Unique and Sum
- Inserting data from controller to an array in javascript
- Chart JS how to display an array of data objects as bar chart
- How can I use an array of {x,y} objects to make a chart?
- How to write better code in es6 for formatting an object with array values
- Convert SQLite PHP array into Javascript array?
- Dynamic array javascript
- Using CHARTJS with a JavaScript Array
- Array of objects condensed into array of unique objects with nested array
- Angular - change objects to array and make it listen to on change
- JavaScript array value to chart.js graph as stacked graph
- How to properly unpack data from PHP array encoded as JSON from a JavaScript file
- Javascript 2D array getting each element
- How to sum the array value in javascript like chartjs data array and input value sum
- is it possible to sum up the properties of an array of objects and to filter it according to another property?
- How to push an array into an Object which is inside of another array?
- Sum array of objects value based on month - ReactJS
More Query from same tag
- Using associative PHP array in JS to later on use in chart generated via chart.js
- In Stacked horizontal bar chart how to remove the vertical line in Chart.js?
- Chartjs Legend Styling
- Chart.js how to set cutoutPercentages for each dataset
- Connect 2 line in chart using chartjs
- want to provide a space between the maximum value and the graph
- attempting to change height and width of canvas for chart
- "Process is not defined" with react-chartjs-2 CDN
- Chart is not rendering properly time axis
- Create multiple dynamic stacked chart using chart.js in Angular 10?
- ChartJS 2.0 - Huddle labels on pie chart
- How to disable click in graph ChartJS
- Creating charts using chart.js
- ChartJs chart won't update new values
- Chart.js 3.5.1 Attribute question about zeroLineColor
- Chart does not display on webpage in Django app (with Chart.js)
- Move y-Axis and hide in Chart.JS V3
- chart.js, after each update, avoid scrolling to top position
- chart.js sum of the last 3h datavalues in a line chart
- X and Y axis labels not displaying on line chart (Chart.js)
- Chart.js maxBarThickness option not working
- What is the correct way to send 2 parameters in socket.io using lambdas? (I get undefined when printing in client and server)
- How to show xaxis lable o only data point and hide all others?
- Chartjs animate x-axis displaying data incorrectly in mac device
- Chartjs Line chart options display increase and decrease percentage between each datapoint
- chartjs: trying to rotate the y-Axis label
- get yLabel value onclick chart js
- Live Update Callback -> afterTitle with Array via JSON file
- How to add label on chart.js on each point
- How to change React line chart tooltip title font family in chart.js