I'm struggling with changing default realtime from streaming plugin for chart.js. Only what I need is "moving chart" which refresh data every 1 second and display my data on X and Y axis.
Ultimately I want to display the simulation time from the simulink model in seconds. I have the actual time in my vuex so just need to somehow convert the realtime to time from the simulation.
simuTime() {
return this.$store.getters.simulationTime
}
},
mounted() {
const ctx = this.$refs.mychart
const data = {
labels: [],
datasets: [
{
label: "Mains_1_Voltage",
data: [],
backgroundColor: "rgba(54, 162, 235, 0.2)",
borderColor: "rgba(75, 192, 192, 1)",
borderWidth: 1,
},
{
label: "Mains_1_Frequency",
data: [],
backgroundColor: "rgba(248, 109, 181, 1)",
borderColor: "rgba(163, 109, 181, 1)",
borderWidth: 1,
},
],
}
var config = {
type: "line",
data: data,
options: {
scales: {
x: {
type: 'realtime',
realtime: {
delay: 1000,
onRefresh: chart => {
chart.data.datasets[0].data.push({
//this doesn't work after changing from Date.now()
x: this.simuTime,
y: this.V1[0].value
})
chart.data.datasets[1].data.push({
//this doesn't work after changing from Date.now()
x: this.simuTime,
y: this.F1[0].value
})
}
}
},
y: {
beginAtZero: true,
},
},
},
}
const myChart = new Chart(ctx, config);
myChart
this.simu_time_interval = setInterval(() => {
this.$store.dispatch('calculateSimulationTime')
}, 500);
},
beforeUnmount() {
clearInterval(this.simu_time_interval)
}
};