Uncaught TypeError: google.visualization.TreeMap is not a constructor

Viewed 36

Hi i am facing this error while running with the react-google-charts while using the react-google-charts, any help would be helpful.

     // Instantiate and draw our chart, passing in some options.
 const tree = new google.visualization.TreeMap(document.getElementById('chart_div'));
tree.draw(data, {minColor: '#f00',midColor: '#ddd',maxColor: '#0d0',headerHeight: 15,fontColor: 'black',showScale: true}
)
;setChart(tree);}}, [google, chart]);return (<>{!google && <Spinner />}<div id="chart_div" className={!google ? 'd-none' : ''} /></>)}

CodeSandbox link

Thanks:)

1 Answers

line 21, the 'treemap' package needs to be loaded.

window.google.charts.load("current", { packages: ["corechart"] });

change to...

window.google.charts.load('current', {packages: ["treemap"]});

or...

window.google.charts.load('current', {packages: ["corechart", "treemap"]});
Related