Merge pull request 'resolved chart data bug' (#15) from realTimeVisulization into main
Reviewed-on: http://185.100.212.76:7776/Dwinzo-Beta/Dwinzo_dev/pulls/15
This commit is contained in:
commit
bbe26a3cb6
|
@ -201,18 +201,16 @@ const LineGraphComponent = ({
|
||||||
const { measurements, setMeasurements, updateDuration, duration } = useChartStore();
|
const { measurements, setMeasurements, updateDuration, duration } = useChartStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if ( measurements.length > 0 ) {
|
|
||||||
const socket = io("http://192.168.0.192:5010");
|
|
||||||
|
|
||||||
|
const socket = io("http://192.168.0.192:5010");
|
||||||
|
|
||||||
|
if ( measurements.length > 0 ) {
|
||||||
var inputes = {
|
var inputes = {
|
||||||
measurements: measurements,
|
measurements: measurements,
|
||||||
duration: duration,
|
duration: duration,
|
||||||
interval: 1000,
|
interval: 1000,
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('graphHHHHHHHHHHHHHHHHHHHHHHHHHHHHH',inputes);
|
|
||||||
|
|
||||||
|
|
||||||
// Start stream
|
// Start stream
|
||||||
const startStream = () => {
|
const startStream = () => {
|
||||||
socket.emit("lineInput", inputes);
|
socket.emit("lineInput", inputes);
|
||||||
|
@ -226,23 +224,24 @@ const LineGraphComponent = ({
|
||||||
|
|
||||||
// Extract timestamps and values
|
// Extract timestamps and values
|
||||||
const labels = responceData.time;
|
const labels = responceData.time;
|
||||||
const datasets = data.measurements.map((measurement: any) => ({
|
const datasets = measurements.map((measurement: any) => {
|
||||||
label: `${measurement.name}.${measurement.fields}`,
|
const key = `${measurement.name}.${measurement.fields}`;
|
||||||
data: responceData[`${measurement.name}.${measurement.fields}`]?.values || [],
|
return {
|
||||||
backgroundColor: themeColor[0] || "#5c87df",
|
label: key,
|
||||||
borderColor: themeColor[1] || "#ffffff",
|
data: responceData[key]?.values ?? [], // Ensure it exists
|
||||||
borderWidth: 2,
|
backgroundColor: themeColor[0] || "#5c87df",
|
||||||
// fill: false,
|
borderColor: themeColor[1] || "#ffffff",
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
|
|
||||||
setChartData({ labels, datasets });
|
setChartData({ labels, datasets });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.off("lineOutput");
|
socket.off("lineOutput");
|
||||||
socket.emit("stop_stream"); // Stop streaming when component unmounts
|
socket.emit("stop_stream"); // Stop streaming when component unmounts
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}, [measurements, duration]);
|
}, [measurements, duration]);
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
|
|
Loading…
Reference in New Issue