简体   繁体   中英

Highcharts w/React - rendering div not found in JSX

I'm trying to use Highcharts with my web application, which is written in React. Highcharts is rendered via a div tag.

I'm rendering everything on my page (ie the panels, input fields, buttons, tables, dropdowns, etc) from my JSX file. When I try to stick a div tag into my JSX with an id or class to link it to the Highcharts JavaScript, I get an error message in my console (Highcharts error #13) that the rendering div is not found.

   render() {
     return ( <div>
      <div id="container"></div>
      </div>
       );
      }
     }

However, when I stick a div tag into my HTML with an id or class linking it to my Highcharts JavaScript, I can get the chart to show up on the page, but I want it inside my JSX so I can place it inside the panels, containers, etc I have in my JSX.

To answer my own question here, the problem was that the render function is called after highcharts attempts to look for the div. You can either put the chart rendering code in the componentDidMount() section, put a timer on it, or render the highcharts code directly using dangerouslySetInnerHTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM