D
D
Dmitry Esin2018-09-13 12:47:49
JavaScript
Dmitry Esin, 2018-09-13 12:47:49

How to generate missing data for date range?

There is an array of objects with data for drawing a graph.
There are startDate and endDate variables in string format.
You need to draw this data on the chart, but you need to draw a segment, taking into account the startDate and endDate variables.
How to do this - you need to push elements with empty values ​​\u200b\u200binto an array with data.

Source array:

const widgetData = [
  {name: "something", value: 14, date: "02.08.2018"},
  {name: "something", value: 43, date: "03.08.2018"},
  {name: "something", value: 44, date: "04.08.2018"},
  {name: "something", value: 38, date: "05.08.2018"}
];

Variables with dates:

let startDate = '01.08.2018';
let endDate = '25.08.2018';

I have momentjs, but somehow there is no whole picture of how to proceed.

Should get:

[
  {name: "something", value: 0, date: "01.08.2018"},
  {name: "something", value: 14, date: "02.08.2018"},
  {name: "something", value: 43, date: "03.08.2018"},
  {name: "something", value: 44, date: "04.08.2018"},
  {name: "something", value: 38, date: "05.08.2018"},
  {name: "something", value: 0, date: "06.08.2018"}
  ...
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
davidnum95, 2018-09-13
@SunDeath

You can do this https://jsfiddle.net/sbah1mxn/22/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question