ReactJS:导入数据后重新图表不渲染线

问题描述

我已经设法获取并渲染图表上的图。但是,该行没有显示,我不知道为什么。这是我的代码

从 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...