How to create a HighCharts chart in react

前端 未结 3 1064
-上瘾入骨i
-上瘾入骨i 2021-01-16 13:27

How can I create a component with a HighCharts chart, that create the chart ones on the first render and only update the series data when new data comes in using chart

3条回答
  •  耶瑟儿~
    2021-01-16 13:52

    getInitialState(){
            return({
                config:{
                    /* HighchartsConfig */
                    xAxis: {
                        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
                    },
                    series: [{
                        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 295.6, 454.4]
                    }]
                },
            })
        },
    
    componentDidMount(){
            let self = this;
            setTimeout(function () {
                self.setState({
                    config:{
                        /* HighchartsConfig */
                        xAxis: {
                            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May']
                        },
                        series: [{
                            data: [29.9, 71.5, 106.4, 129.2, 144.0]
                        }]
                    },
                })
                // chart.xAxis[0].setCategories(['Jan', 'Feb', 'Mar', 'Apr', 'May'],true)
                // chart.series.addPoint({x: 10, y: 12});
                // chart.series.setData([29.9, 71.5, 106.4, 129.2, 144.0],true)
            },3000)
        },
    
    
    

    just like this,it works for me.

提交回复
热议问题