Comments (9)
Hey, the chart is stored as a property of the component, I haven't added a getter for it. You can grab it using the component ref for now.
Hope that helps.
from react-google-charts.
Could you give me an example ? I'm a newby to react world :)
I tried to do next
<div id='extremeIssuesTrendChart' style={{"zIndex": 2}}>
<Chart ref='googleChart' chartType = "ComboChart" data = {data} options = {options} graph_id = "ScatterChart" width={"100%"} height={"400px"} legend_toggle={true} />
</div>
And then, in another component, in componentDidMount()
method i do when i try to get the image :
const chart = ReactDOM.findDOMNode(this.refs.googleChart);
const img = chart.getImageURI();
console.log('Image is ', img);
And i get Uncaught TypeError: Cannot read property 'getImageURI' of null
error message in console.
from react-google-charts.
Sure, this gist should do it : https://gist.github.com/RakanNimer/327a347411253806e5530544c3a4f7f5
from react-google-charts.
Thanks a lot for helping me , but i still have very weird behaviour. My component looks like this :
import React from 'react';
import {render} from 'react-dom'
import {Chart} from 'react-google-charts'
class ExtremeIssuesTrendChart extends React.Component {
componentDidMount = () => {
console.log('Props in trend chart are', this.props);
console.log('Chart ', this.GoogleChart);
const googleChart = this.GoogleChart;
for (let prop in googleChart) {
if (googleChart.hasOwnProperty(prop)){
console.log('Prop is', prop, 'And value is ', googleChart[prop]);
}
}
console.log('Chart data is ', this.GoogleChart['chart']);
this.props.setChartUri(this.GoogleChart.chart.getImageURI())
};
render() {
const options = {
title : 'Extreme Issues trend',
vAxis: {title: 'Amount'},
hAxis: {title: 'Fix Version'},
seriesType: 'bars'};
const data = [];
data.push(['FixVersion', 'Bug', 'Total', 'Other']);
this.props.stories.map(fixVersionDetails => {
const detailsArray = [];
detailsArray.push(fixVersionDetails.fixVersion);
detailsArray.push(fixVersionDetails.bug);
detailsArray.push(fixVersionDetails.total);
detailsArray.push(fixVersionDetails.other);
data.push(detailsArray);
});
return (
<div id='extremeIssuesTrendChart' style={{"zIndex": 2}}>
<Chart ref={(ref) => this.GoogleChart = ref}
chartType = "ComboChart"
data = {data}
options = {options}
graph_id = "ScatterChart"
width={"100%"}
height={"400px"}
legend_toggle={true}
/>
</div>
);
}
}
export default ExtremeIssuesTrendChart;
In console i see next output :
Chart Chart {props: Object, context: Object, refs: Object, updater: Object, state: Object…}
Prop is props And value is Object {chartType: "ComboChart", data: Array[9], options: Object, graph_id: "ScatterChart", width: "100%"…}
Prop is context And value is Object {}
Prop is refs And value is Object {}
Prop is updater And value is Object {}
Prop is state And value is Object {graphID: "ScatterChart"}
Prop is chart And value is null
Prop is wrapper And value is null
Prop is hidden_columns And value is Object {}
Prop is dataTable And value is []
Prop is _reactInternalInstance And value is ReactCompositeComponentWrapper {_currentElement: Object, _rootNodeID: 0, _compositeType: 0, _instance: Chart, _hostParent: ReactDOMComponent…}
Chart data is null
Uncaught TypeError: Cannot read property 'getImageURI' of null
But when i look into the GoogleChart object in developer tools, i see that chart has properties ( How is this possible ???? )
from react-google-charts.
You have to wait until the chart is initialised before accessing it. You're trying to access the chart on componentDidMount but the chart is not ready yet. Since it's the same object, it's being logged correctly after the chart is ready.
I will try to add an onReady prop to the component later this week. Meanwhile if you want a temporary ugly hack use a setTimeout before grabbing the Chart.
from react-google-charts.
Thanks, that worked :) Had to add 500 ms timeout and it worked for me. Could you comment on this issue when you add onReady prop ? Then we would close this issue.
Thanks again for such a quick response and help.
from react-google-charts.
Happy to help :)
Turns out there's no need to change the code, you can just listen to the ready
event from google charts. I updated the gist accordingly :
https://gist.github.com/RakanNimer/327a347411253806e5530544c3a4f7f5
Cheers.
from react-google-charts.
Hi, thanks for the tip. I'm having some troubles with this code. I've added chart_events into componentDidMount and added this.setState({'chart_events: chart_events})
, but in render method i get null
for this.state. Therefore my component fails when i try to specify it as :
<div id='extremeIssuesTrendChart' style={{"zIndex": 2}}>
<Chart ref={(ref) => this.GoogleChart = ref}
chartType = "ComboChart"
data = {data}
options = {options}
graph_id = "ScatterChart"
width={"100%"}
height={"400px"}
legend_toggle={true}
chartEvents = {this.state.chart_events}
/>
</div>
from react-google-charts.
Actually, i just found a solution for this :) I just added :
constructor() {
super();
this.state = {'chart_events': undefined};
}
Thanks a lot for your help :)
from react-google-charts.
Related Issues (20)
- [Bug]: Not getting selected iterate node on react_google_charts Treemap
- Add support for Marker GeoCharts and ISO-3166:2 district codes
- Options are not documented
- Allow to close tooltips programmatically
- Storage size formats
- [Bug]: addOneTimeListener this doesn't seem to be supported?
- [Bug]: Can't seem to get MutationObserver to work inside an event, but it works with the underlying library
- [Bug]: Bar Chart (and Other?) Examples Broken
- [Bug]: No Material UI Support?
- [Bug]: Scatter chart options not recognized (Material)
- Remove deprecated dependency react-scripts
- [Bug]: Diff tooltips prefix option
- [Bug]: Stacked Column Chart - Show Annotation on Bars HOT 1
- [Bug]: ReferenceError: Property 'document' doesn't exist
- [Bug]: sort and page events are not working with Table chart HOT 1
- [Bug]: Geo chart (maybe other) doesn't respect React@18 StrictMode
- [Bug]: Select event is not working in strict mode. HOT 1
- [Bug]: loadingStatus state for react-google-charts is set as loading permanantly HOT 5
- [Bug]: Org Chart does not render label on top node HOT 1
- [Bug]: Charts with spreadsheets does not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-google-charts.