I am currently working on creating a timeline map using echarts js. However, I am facing difficulty in figuring out how to create the necessary 'options'. When I run the following code, I get the 'option' as shown below:
import axios from 'axios'
const data = []
const date= []
let options= []
axios.get('https://data.nepalcorona.info/api/v1/covid').then((res) => {
const array = res.data
const groups = array.reduce((groups, info) =>{
const date = info.reportedOn;
if (!groups[date]) {
groups[date] = [];
}
groups[date].push(info);
return groups;
}, {});
const groupingDate = Object.keys(groups).map((date) =>{
return{
date: date,
infos: groups[date]
};
})
const sortedData = groupingDate.sort((a,b) => {
var dateA = new Date(a.date) , dateB = new Date(b.date)
return dateA - dateB
})
for(let i=0; i< sortedData.length; i++) {
date.push(sortedData[i].date)
const array = sortedData[i].infos
data.push(array)
}
const points= [];
const newlist = data.map(x => {
points.push([x[0].point.coordinates[0], x[0].point.coordinates[1], x[0].age]);
return {
series:{
data: points.slice(0)
}
}
})
options.push(newlist)
console.log(options)
})
export default {
...
options: [options][0],
...
}
The generated result is displayed below: https://i.sstatic.net/vx1P5.png
However, I do not want an unnecessary array like the one obtained. Instead, I require the 'options' to be in the following format:
options: Object ---baseOption: Object ---options: Array[67]
I hope my explanation is clear and you can assist me with this.