如何解决使用 xstream 和 react-native-svg-charts
我是 React Native 的新手,所以如果我的解释不好请原谅。
我正在尝试制作一个应用程序,该应用程序接收 BLE 数据并将其绘制到图表上。使用“xstream”包接收数据时将数据放入流中,然后使用“stream-to-array”包将此数据放入数组中,我使用的图形库是“react-native” -svg-charts'。
到目前为止,我一直在努力测试从流中获取数据并将其格式化在图表上的能力,因为即使流中有数据也没有显示任何内容。
import React from "react";
import { LineChart,Grid } from "react-native-svg-charts";
import xs from "xstream";
var toArray = require("stream-to-array");
const set = [10,20,30,40];
var stream = xs.fromArray(set);
var data = [];
stream.addListener({
next: (i) => console.log(i),error: (err) => console.error(err),});
toArray(stream,function (err,data) {
assert.ok(Array.isArray(data));
});
class Graph extends React.PureComponent {
render() {
return (
<LineChart
style={{ height: 200 }}
data={data}
animate="true"
svg={{ stroke: "rgb(134,65,244)" }}
contentInset={{ top: 20,bottom: 20 }}
>
<Grid />
</LineChart>
);
}
}
export default Graph;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。