问题描述
我已经设法获取并渲染图表上的图。但是,该行没有显示,我不知道为什么。这是我的代码:
从 API 获取数据
const [error,setError] = useState(null)
const [isLoaded,setIsLoaded] = useState(false)
const [data,setItems] = useState([])
useEffect(() => {
fetch(
'http://api.marketstack.com/v1/inTraday?access_key=YOUR_ACCESS_KEY&symbols=AMC',{
method: 'GET'
}
)
.then(response => response.json())
.then(result => {
setItems(result.data)
setIsLoaded(true)
console.log(result)
})
.catch(err => {
setError(error)
console.error(err)
})
},[])
这是我的折线图代码
<LineChart
width={900}
height={400}
data={data}
margin={{ top: 5,right: 20,bottom: 5,left: 0 }}
>
<XAxis dataKey='date' tickFormatter={formatXAxis} />
<YAxis dataKey='close' />
<Cartesiangrid stroke='#ccc' strokeDasharray='5 5' />
<Line
type='monotone'
dataKey='close'
stroke='##D8A22D'
activeDot={{ r: 8 }}
/>
<Tooltip />
<Legend />
</LineChart>
我检查了文档,我真的无法找出这到底有什么问题。真的很感激一些帮助!谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)