Last active
December 3, 2024 03:20
-
-
Save rakannimer/327a347411253806e5530544c3a4f7f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import {render} from 'react-dom' | |
import {Chart} from 'react-google-charts' | |
export default class App extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
data: [], | |
options: {} | |
}; | |
} | |
componentDidMount() { | |
let options = { | |
title: 'Age vs. Weight comparison', | |
hAxis: {title: 'Age', minValue: 0, maxValue: 15}, | |
vAxis: {title: 'Weight', minValue: 0, maxValue: 15}, | |
legend: 'none', | |
}; | |
let data = [ | |
['Age', 'Weight'], | |
[ 8, 12], | |
[ 4, 5.5], | |
[ 11, 14], | |
[ 4, 5], | |
[ 3, 3.5], | |
[ 6.5, 7] | |
]; | |
let chart_events = [ | |
{ | |
eventName : 'ready', | |
callback : (Chart) => { | |
// Returns Chart so you can access props and the ChartWrapper object from chart.wrapper | |
this.setState({chartImageURI: Chart.chart.getImageURI()}) | |
} | |
} | |
]; | |
this.setState({ | |
'data' : data, | |
'options' : options, | |
'chart_events' : chart_events | |
}); | |
} | |
render() { | |
return <div> | |
<h2>Welcome to React</h2> | |
<Chart chartType = "ScatterChart" | |
data = {this.state.data} | |
options = {this.state.options} | |
graph_id = "ScatterChart" | |
width={"100%"} | |
height={"400px"} | |
legend_toggle={true} | |
chartPackage= {['controls']} | |
chartEvents = {this.state.chart_events} | |
ref={(ref) => this.GoogleChart = ref} | |
/> | |
<div onClick={()=>{ | |
this.setState({chartImageURI: this.GoogleChart.chart.getImageURI()}); | |
}}> <h1>CLICK ME TO TURN CHART INTO PNG </h1> </div> | |
<div> | |
Chart image in base64 : | |
{this.state.chartImageURI} | |
</div> | |
<div> | |
<h2>Chart as png</h2> | |
<img src={this.state.chartImageURI} /> | |
</div> | |
</div> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work like this anymore, where do I find getImageURI?