你好,我有一个折线图,我应该在其中显示动态数据,如果他们不向我传递数据,那只是一条直线。
我遇到的问题是我不知道如何将道具传递给折线图
var data `[
{
"name": "Samantha White",
"id": "484567489sda",
"address": "4116 Barton Creek Boulevard Austin, TX 78735 USA",
"logo": "https://sssssss.s3.amazonaws.com/ssss/express.png",
"occupancy": {
"capacity": 150,
"occupancy": 0,
"percentage": 0
},
"alerts": {
"conglomerations": 0,
"occupancy": 0
},
"visits": 2721
"plot": []
},
{
"name": "Jacqueline Wells",
"id": "sdasdx45616a4dsa5",
"address": "s15035 Highview Road Grand Junction, CO 81504 USA",
"store_logo": "ssssss.s3.amazonaws.com/ssss/lider.png",
"occupancy": {
"capacity": 150,
"occupancy": 0,
"percentage": 0
},
"alerts": {
"conglomerations": 0,
"occupancy": 0
},
"visits": 2069,
"plot": [9, 29, 48, 52, 88, 107, 130, 127, 122, 157, 165, 172, 211, 214, 267, 296, 331, 353, 371, 381]
}
]`;
function App() {
const [tiendas, setTiendas] = useState(JSON.parse(data));
const [showTiendas, setShowTiendas] = useState(false)
useEffect(() => {
setTiendas(JSON.parse(data));
}, []);
return (
<div className="w-full ">
<Menu showTiendas={setShowTiendas} menuData={tiendas} tiendasSet={setTiendas} />
{showTiendas && tiendas.map((tienda) => (
<Card key={Math.random()} {...tienda}></Card>
))}
</div>
);
}
export default App;
图表的数据将是plot,在卡组件中我命令调用图表,这将是图表的代码,我不知道如何从图表发送调用plot,现在图表有随机数
import React, { useState } from "react";
import { scaleLinear, scaleBand } from "d3-scale";
import Line from "./Line";
import { line, curveMonotoneX } from "d3-shape";
import { extent } from "d3-array";
function Chart(props) {
const [data, setData] = useState(
[
Math.random()*30,
Math.random()*30,
Math.random()*30,
Math.random()*30,
Math.random()*30,
Math.random()*30,
Math.random()*30,
]
);
const parentWidth = 125;
const margins = {
top: 20,
right: 20,
bottom: 20,
left: 20
};
慕的地8271018
GCT1015
相关分类