【发布时间】:2020-03-19 13:43:40
【问题描述】:
是否可以使用 json 数据获取 highcharts,https://www.npmjs.com/package/highcharts?我正在使用反应应用程序。我尝试这种静态方式:
import React from 'react'
import { render } from 'react-dom'
import Highcharts from 'highcharts'
import HighchartsReact from 'highcharts-react-official'
const options = {
title: {
text: 'My chart'
},
series: [{
data: [1, 2, 3]
}]
}
const App = () => <div>
<HighchartsReact
highcharts={Highcharts}
options={options}
/>
</div>
render(<App />, document.getElementById('root'))
它可以工作,但我希望显示我的数据。 我的 json 看起来像:
[
{
"Date": "2019-10-29",
"Price1": 55.34,
"Price2": 61.05,
"Price3": 1.791
},
{
"Date": "2019-10-28",
"Price1": 55.6,
"Price2": 60.39,
"Price3": 1.784
}
]
【问题讨论】:
-
componentDidMount->fetch数据 ->setState-> 将state.options传递给HighcartsReact组件
标签: json reactjs api highcharts