I am trying to hook data into apexchart chart
<apexchart
type="area"
height="350"
:options="chartOptions"
:series="series">
</apexchart>
I have an array of data, but for plotting a graph I need to split it into 3 different arrays for plotting a graph, but I don't know how to do it using JS
i get an array like this from api
dataOverview = [
{
"id": 1,
"successfullySyngranized": 1,
"unsuccessfullySynchronized": 5,
"timeStamp": "2020-11-01T00:00:00"
},
{
"id": 2,
"successfullySyngranized": 2,
"unsuccessfullySynchronized": 4,
"timeStamp": "2020-11-02T00:00:00"
},
{
"id": 3,
"successfullySyngranized": 3,
"unsuccessfullySynchronized": 3,
"timeStamp": "2020-11-03T00:00:00"
},
{
"id": 4,
"successfullySyngranized": 4,
"unsuccessfullySynchronized": 2,
"timeStamp": "2020-11-04T00:00:00"
},
{
"id": 5,
"successfullySyngranized": 5,
"unsuccessfullySynchronized": 1,
"timeStamp": "2020-11-05T00:00:00"
}];
as a result, I need to get such arrays
var series = [];
var timeStamp = [];
and insert them into the chart settings
data() {
return {
dataOverview: [],
series: [] // insert series objects,
chartOptions: {
//...
// some options
//...
xaxis: {
type: "datetime",
categories: [ // insert timeStamp array
// "2020-11-01T00:00:00",
// "2020-11-02T00:00:00",
// "2020-11-03T00:00:00",
// "2020-11-04T00:00:00",
// "2020-11-05T00:00:00"
]
},
//...
// some options
//...
}
}
}
beforeMount() {
this.onGetDataOverview();
},
methods: {
onGetDataOverview() {
this.$axios
.$get(
this.$store.getters["store/getApiPath"] + "/Analyst/GetOverviewData"
)
.then(response => {
this.dataOverview = response;
const seriesOne = this.dataOverview.map(
({ successfullySyngranized }) => successfullySyngranized
);
const seriesTwo = this.dataOverview.map(
({ unsuccessfullySynchronized }) => unsuccessfullySynchronized
);
const series2 = [
{ name: "series1", data: seriesOne },
{ name: "series2", data: seriesTwo }
];
this.series = series2;
//Here I am trying to insert time data, however the graph does not start
let xaxis = {
...this.chartOptions.xaxis,
categories: this.dataOverview.map(({ timeStamp }) => timeStamp)
};
this.chartOptions = { ...this.chartOptions, ...{ xaxis: xaxis } };
})
when inserting time data - the graph is not built, however if I explicitly indicate the time in the declaration of variables - the graph is built
but also I need to do tracking so that the graph moves when new data is received i.e. use computed