0

I'm trying to run a small chart to test Highchart's within a project created in visual studio and am encountering a

TypeError: Cannot read property 'nodeName' of null a.Chart.getArgs L:/Google Drive/Open university work/Year three modules/TM4/analitics/ReactApp/ReactApp/ClientApp/node_modules/highcharts/highcharts.js:266 error message.

The project is in React and has the following dependencies

"bootstrap": "^3.3.7",
"highcharts": "^7.1.1",
"highcharts-react-official": "^2.1.3",
"react": "16.4.0",
"react-bootstrap": "^0.31.5",
"react-dom": "^16.0.0",
"react-router-bootstrap": "^0.24.4",
"react-router-dom": "^4.2.2",
"react-scripts": "1.0.17",
"rimraf": "^2.6.2"

So far I have tried to create a fresh react project and copy this component into it after installing the dependencies where I omitted bootstrap and react router. This displayed the graph as expected, so, I now know that the component works as intended.

I have then tried to reinstall Highchart's and react Highcharts in the original project to no success.

I looked on a number of other posts on stack overflow and found similar errors, however, couldn't find a solution in those questions.

import React from 'react';
import { Component } from 'react';
import { render } from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import { renderToString } from 'react-dom/server';



export default class Hichart extends Component {

    render(){
        return (<div>
            <HighchartsReact highcharts={Highcharts} options={{
                title: {
                    text: 'My chart'
                },
                series: [{
                    data: [1, 2, 3]
                }]
            }} /></div > );
    }
}

I expected a graph to be rendered instead I got a long error message highlight parts of highchart.js file.

× TypeError: Cannot read property 'nodeName' of null a.Chart.getArgs L:/Google Drive/Open university work/Year three modules/TM4/analitics/ReactApp/ReactApp/ClientApp/node_modules/highcharts/highcharts.js:266

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
M Leipper
  • 277
  • 5
  • 20

1 Answers1

0

Try this refactor.

"import { render } from 'react-dom';" is used when you are rendering the entire React app on an html element.

import React from 'react';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import { renderToString } from 'react-dom/server';


class HichartComponent extends React.Component {
  
  render(){
    const options = {
      title: {
        text: 'My chart'
      },
      series: [{
        data: [1, 2, 3]
      }]
    }
    
    return (
      <div>
        <HighchartsReact
          highcharts={Highcharts}
          options={options}
        />
      </div>
    );
  }
}

export default HichartComponent;
  • Many thanks for attempting to help me. I've given this a go and the application still throws the same error. :( – M Leipper May 08 '19 at 10:37