javascript - 带有 vue-chartjs 的实时图表
问题描述
我有一些设备正在尝试从他们收集的数据中构建实时图表。目前我正在尝试读取并显示他们的 wifi 信号强度,但我无法将它们联系在一起。我将如何根据已发布的数据构建 Xaxis,并绘制 wifi 信号图表?
parsedData 变量的示例
{coreid: "1f0039000547363339343638", data: "-21", published_at: "2018-11-02T17:36:15.794Z", ttl: 60}
家.vue
<template>
<div>
<line-chart :chart-data="chartData" />
</div>
</template>
<script>
import LineChart from '@/components/lineChart'
let wifiSignal = []
export default {
components: {
LineChart
},
data() {
return {
wifiSignal: null,
datacollection: null,
probes: [],
probe: [],
chartData: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December'
],
datasets: [{
label: 'Wifi Signal',
backgroundColor: '#f87979',
data: this.wifiSignal
}]
}
}
},
created() {
this.streamData()
},
mounted() {
// grab probe data
axios.get('http://10.10.10.1:8080/v1/devices')
.then((res) => {
(this.probes = res.data)
// console.log(res.data)
}).catch((error) => {
console.log(error.res);
});
},
methods: {
streamData() {
// LIVE PUSH EVENTS
if (typeof (EventSource) !== "undefined") {
var eventSource = new EventSource(
"http://10.10.10.1:8080/v1/Events");
eventSource.addEventListener('open', function (e) {
console.log("Opened connection to event stream!");
}, false);
eventSource.addEventListener('error', function (e) {
console.log("Errored!");
}, false);
eventSource.addEventListener('WiFi Signal', function (e) {
var parsedData = JSON.parse(e.data);
let cat = parseInt(parsedData.data)
console.log(cat)
wifiSignal.push(cat);
}, false);
}
}
},
};
</script>
线图.js
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default {
extends: Line,
mixins: [reactiveProp],
props: ['options'],
mounted () {
// this.chartData is created in the mixin.
// If you want to pass options please create a local options object
this.renderChart(this.chartData, this.options)
}
}
解决方案
推荐阅读
- php - MYSQL PHP JSON 返回每个产品的所有图像
- mysql - 如何解密存储在 mySQL 数据库中的键值数据?
- wso2 - EI 7.0.1 是否包含 BPS?
- vim - 如何一次在 YAML 文件的多行中插入同一行
- node.js - mongodb findMany by id 在数组中的所有记录中
- r - 结合 r-handler 和 tls
- fortran - 复数与实数变量的 Fortran 性能
- spring - Spring task:scheduled 或 @Scheduler 限制作业在多个实例中运行
- javascript - 将条件用户访问放在 ajax 上
- vba - 带空格的超链接