Giter VIP home page Giter VIP logo

Comments (9)

rakannimer avatar rakannimer commented on May 14, 2024

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.

azakordonets avatar azakordonets commented on May 14, 2024

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.

rakannimer avatar rakannimer commented on May 14, 2024

Sure, this gist should do it : https://gist.github.com/RakanNimer/327a347411253806e5530544c3a4f7f5

from react-google-charts.

azakordonets avatar azakordonets commented on May 14, 2024

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 ???? )
screenshot 2016-09-02 09 45 47

from react-google-charts.

rakannimer avatar rakannimer commented on May 14, 2024

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.

azakordonets avatar azakordonets commented on May 14, 2024

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.

rakannimer avatar rakannimer commented on May 14, 2024

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.

azakordonets avatar azakordonets commented on May 14, 2024

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.

azakordonets avatar azakordonets commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.