0

i have an array to be mapped to an array to show in graph, the array values change when we change the date, But for me the new value is added with the previous value,

let salesToday_result = self.graphPlotting(res.today);
salesToday_result[0].map(item =>{self.salesChartLabels.push(moment(moment.utc(item).toDate()).format("hh A"))})
self.salesChartData[0]['data'] = salesToday_result[1];
console.log('self.salesChartLabels',self.salesChartLabels)

As you can see in the image below,

24hr Data is added every time i change the date

enter image description here

enter image description here

enter image description here

How it can be solved,(if more code needed,can be provided)

1
  • More code is needed because we don't know your model. Please provide a minimal reproducible example so that we don't have to deal with your business logic, and only the technical part. Commented Jun 7, 2018 at 7:40

2 Answers 2

1

You are pushing onto the array self.salesChartLabels you need to clear the array before you start pushing into, if you want to reset the labels.

If you want to completely reset the labels and graphPlotting in synchronous, you can try this:

let salesToday_result = self.graphPlotting(res.today);
self.salesChartLabels = [];
salesToday_result[0].map(item =>{self.salesChartLabels.push(moment(moment.utc(item).toDate()).format("hh A"))})
Sign up to request clarification or add additional context in comments.

Comments

1

Since you're using map, maybe what you want is to do as follows:

let salesToday_result = self.graphPlotting(res.today);
self.salesChartLabels = salesToday_result[0].map(item => moment(moment.utc(item).toDate()).format("hh A"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.