TradingPal / react-native-highcharts

📈 Add Highcharts charts to react-native app for IOS and Android
https://github.com/TradingPal/react-native-highcharts
256 stars 158 forks source link

Can't access this.props in load #33

Closed nidhi-tandon closed 1 year ago

nidhi-tandon commented 7 years ago
render(){
            let conf={
                chart: {
                    type: 'spline',
                    animation: Highcharts.svg, // don't animate in old IE
                    marginRight: 10,
                    events: {
                        load:function(){
                            var series = this.series[0];
                            setInterval(() =>{
                                var x = new Date().getTime() // current time
                                y = this.props.y
                                series.addPoint([x,y], true, true);
                            }, 900);
                        }
                    }
                },
                title: {
                    text: 'Live random data'
                }
}
}

Cant access this.props.y in load function and I cant even access constructor variable. Thanks for the help in advance.

Infinity0106 commented 6 years ago

try something like this

render(){
            let self=this;
            let conf={
                chart: {
                    type: 'spline',
                    animation: Highcharts.svg, // don't animate in old IE
                    marginRight: 10,
                    events: {
                        load:function(){
                            var series = this.series[0];
                            setInterval(() =>{
                                var x = new Date().getTime() // current time
                                y = self.props.y
                                series.addPoint([x,y], true, true);
                            }, 900);
                        }
                    }
                },
                title: {
                    text: 'Live random data'
                }
}
}

let me know if this worked for you, and thanks in advance for using the component

farshidbakh commented 6 years ago

Hello Nidhi-tandon,

Any update on this issue? Because I am trying to do the similar thing. I would appreciate if you post your solution to this forum. I tried the suggested solution above and it didn't work for me. Please let us know. Thanks,

Infinity0106 commented 6 years ago

I dont know how to solve it but what happens is that the complete object is parsed inside the html then concatenated, so the text would be literal not connecting the variables because in the html cant find the variable self.props.y, try passing it as a string maybe

nidhi-tandon commented 1 year ago

Closing this as I have lost context of this issue.