TypeError: Highcharts.mapChart is not a function
TypeError: Highcharts.mapChart is not a function
I am trying to plot a highmap in react using typescript. I have additionally loaded the highcharts types which include highmaps.
class InvestmentChart extends React.Component {
componentDidMount() {
Highcharts.mapChart("investment", {
chart: {
...
Cheers
See live here.
1 Answer
1
Based on the readme, it looks like you need to do:
import * as Highcharts from 'highcharts/highmaps';
instead of:
import * as Highcharts from 'highcharts';
I tried this in CodeSandbox and it seemed to get past the point where you were stuck.
DefinitelyTyped appears to have some typings for Highmaps, though they are out of date. The following method of importing Highmaps seems to get as far as the previous method at runtime in CodeSandbox and will use the typings:
import * as Highcharts from "highcharts";
import MapFactory = require("highcharts/modules/map");
(MapFactory as any)(Highcharts);
New CodeSandbox. Locally, I am still getting a type error because of the out-of-date declarations (subtitle
is not recognized), but you can //@ts-ignore
it. I don't know why this error isn't appearing on CodeSandbox.
subtitle
//@ts-ignore
Well ok, but there is no such module. That is the result when trying in CodeSandbox
– Peterhack
Aug 31 '18 at 13:09
See the CodeSandbox I linked where it's working for me.
– Matt McCutchen
Aug 31 '18 at 13:19
You can actually see the map of germany?
– Peterhack
Aug 31 '18 at 13:21
No, but I see the title "Highmaps basic demo" that demonstrates that the
Highcharts.mapChart
call is doing something. Maybe you are not specifying the map correctly, but that's a different issue.– Matt McCutchen
Aug 31 '18 at 13:28
Highcharts.mapChart
On my local environment, I still do not get it past that point. The issue is:
Could not find a declaration file for module 'highcharts/highmaps'. 'D:/Programming/Bitbucket/report-example/node_modules/highcharts/highmaps.js' implicitly has an 'any' type.
Is this related to the same issue as in CodeSandbox that there is no such modul?– Peterhack
Sep 6 '18 at 11:46
Could not find a declaration file for module 'highcharts/highmaps'. 'D:/Programming/Bitbucket/report-example/node_modules/highcharts/highmaps.js' implicitly has an 'any' type.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Always post relevant code in the question itself. You can still use code snippet here in SO.
– Bhojendra Rauniyar
Aug 31 '18 at 12:18