How can I pass values from Highcharts event callbacks (click, mouseOver, mouseOut) back to React component member function?How can I pass a parameter to a setTimeout() callback?How to return value from an asynchronous callback function?Sending Ember Highcharts events back to parent componentHighcharts - javascript function on event click gives error e.call is not a functionReact Component, Highstock: Synchronize multiple charts?use on click for pie react-highcharts without overriding default onclick functionreact-jsx-highchart: Capture custom panning event in component based HighchartDynamically update Highcharts chart in reactError: The following params are required: Client ID, Client Secret on clarifai api on React

Do landing gear doors need repairs after a gear gravity deploy landing?

How accurate is the new appraisal system?

Why are some Mac apps not available on AppStore?

I multiply the source, you (probably) multiply the output!

What should I do about my non-English publications when applying to a University in an English-speaking country?

How does Vivi differ from other Black Mages?

Do Milankovitch Cycles fully explain climate change?

SCOTUS - Can Congress overrule Marbury v. Madison by statute?

What happens when a caster loses concentration on a banished creature?

Gas pipes - why does gas burn "outwards?"

Has any object launched from Earth permanently gone into the sun?

How would a village use its river that it shares with another village downstream?

How can I fix a framing mistake so I can drywall?

Why is the Tm defined as the temperature at which 50% of dsDNA has changed into ssDNA?

Tear out when plate making w/ a router

I see your BIDMAS and raise you a BADMIS

CBP interview, how serious should I take it?

I changed a word from a source, how do I cite it correctly?

How would two worlds first establish an exchange rate between their currencies

Dublin to Belfast by bus. Where do I get my passport stamped

2.5 year old daughter refuses to take medicine

Guitar beginner - What does this card show?

Is it appropriate for a professor to require students to sign a non-disclosure agreement before being taught?

What is this dollar sign ($) icon in my Menu Bar?



How can I pass values from Highcharts event callbacks (click, mouseOver, mouseOut) back to React component member function?


How can I pass a parameter to a setTimeout() callback?How to return value from an asynchronous callback function?Sending Ember Highcharts events back to parent componentHighcharts - javascript function on event click gives error e.call is not a functionReact Component, Highstock: Synchronize multiple charts?use on click for pie react-highcharts without overriding default onclick functionreact-jsx-highchart: Capture custom panning event in component based HighchartDynamically update Highcharts chart in reactError: The following params are required: Client ID, Client Secret on clarifai api on React






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I can create a chart and pass a function for the mouseOver event that simply logs the x and y values of the marker that I hover over:



// Works

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
console.log(point);





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


Ultimately I want to be able to pass that point back to my component and use it elsewhere in my app.



The simple idea of calling a function in my component from within the event does not work -- the this that I pass in the plotOptions no longer refers to my component but to the point in the chart:



// Does not work
// Uncaught TypeError: this.handleMouseOver is not a function

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

handleMouseOver = point =>
console.log(`handleMouseOver gets $point`);


render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
this.handleMouseOver(point); <--- not the `this` of my component





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


No surprise, the error that I get in the browser when I hover over a point is



Uncaught TypeError: this.handleMouseOver is not a function


Any suggestions?



Thanks.










share|improve this question


























  • One solution I found is to put const foo = this.handleMouseOver; at the start of the render function and call foo(point) in the plotOptions. This avoids using this in the plotOptions to refer to the component. Seems a bit of a cheat, though. Is there something more elegant?

    – Robert
    Mar 28 at 8:18


















2















I can create a chart and pass a function for the mouseOver event that simply logs the x and y values of the marker that I hover over:



// Works

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
console.log(point);





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


Ultimately I want to be able to pass that point back to my component and use it elsewhere in my app.



The simple idea of calling a function in my component from within the event does not work -- the this that I pass in the plotOptions no longer refers to my component but to the point in the chart:



// Does not work
// Uncaught TypeError: this.handleMouseOver is not a function

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

handleMouseOver = point =>
console.log(`handleMouseOver gets $point`);


render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
this.handleMouseOver(point); <--- not the `this` of my component





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


No surprise, the error that I get in the browser when I hover over a point is



Uncaught TypeError: this.handleMouseOver is not a function


Any suggestions?



Thanks.










share|improve this question


























  • One solution I found is to put const foo = this.handleMouseOver; at the start of the render function and call foo(point) in the plotOptions. This avoids using this in the plotOptions to refer to the component. Seems a bit of a cheat, though. Is there something more elegant?

    – Robert
    Mar 28 at 8:18














2












2








2








I can create a chart and pass a function for the mouseOver event that simply logs the x and y values of the marker that I hover over:



// Works

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
console.log(point);





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


Ultimately I want to be able to pass that point back to my component and use it elsewhere in my app.



The simple idea of calling a function in my component from within the event does not work -- the this that I pass in the plotOptions no longer refers to my component but to the point in the chart:



// Does not work
// Uncaught TypeError: this.handleMouseOver is not a function

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

handleMouseOver = point =>
console.log(`handleMouseOver gets $point`);


render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
this.handleMouseOver(point); <--- not the `this` of my component





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


No surprise, the error that I get in the browser when I hover over a point is



Uncaught TypeError: this.handleMouseOver is not a function


Any suggestions?



Thanks.










share|improve this question
















I can create a chart and pass a function for the mouseOver event that simply logs the x and y values of the marker that I hover over:



// Works

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
console.log(point);





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


Ultimately I want to be able to pass that point back to my component and use it elsewhere in my app.



The simple idea of calling a function in my component from within the event does not work -- the this that I pass in the plotOptions no longer refers to my component but to the point in the chart:



// Does not work
// Uncaught TypeError: this.handleMouseOver is not a function

import React from 'react';
import render from 'react-dom';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

class App extends React.Component

handleMouseOver = point =>
console.log(`handleMouseOver gets $point`);


render = () =>
const options =
chart:
type: 'spline'
,
title:
text: 'My chart'
,
series: [

data: [1, 2, 1, 4, 3, 6]

],
plotOptions:
series:
point:
events:
mouseOver: function ()
const point = x: this.x, y: this.y ;
this.handleMouseOver(point); <--- not the `this` of my component





;

return (
<div>
<HighchartsReact highcharts=Highcharts options=options />
</div>
)



render(<App />, document.getElementById('root'));


No surprise, the error that I get in the browser when I hover over a point is



Uncaught TypeError: this.handleMouseOver is not a function


Any suggestions?



Thanks.







javascript reactjs highcharts this






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 13:48









Wojciech Chmiel

4,8661 gold badge3 silver badges13 bronze badges




4,8661 gold badge3 silver badges13 bronze badges










asked Mar 28 at 8:00









RobertRobert

7787 silver badges14 bronze badges




7787 silver badges14 bronze badges















  • One solution I found is to put const foo = this.handleMouseOver; at the start of the render function and call foo(point) in the plotOptions. This avoids using this in the plotOptions to refer to the component. Seems a bit of a cheat, though. Is there something more elegant?

    – Robert
    Mar 28 at 8:18


















  • One solution I found is to put const foo = this.handleMouseOver; at the start of the render function and call foo(point) in the plotOptions. This avoids using this in the plotOptions to refer to the component. Seems a bit of a cheat, though. Is there something more elegant?

    – Robert
    Mar 28 at 8:18

















One solution I found is to put const foo = this.handleMouseOver; at the start of the render function and call foo(point) in the plotOptions. This avoids using this in the plotOptions to refer to the component. Seems a bit of a cheat, though. Is there something more elegant?

– Robert
Mar 28 at 8:18






One solution I found is to put const foo = this.handleMouseOver; at the start of the render function and call foo(point) in the plotOptions. This avoids using this in the plotOptions to refer to the component. Seems a bit of a cheat, though. Is there something more elegant?

– Robert
Mar 28 at 8:18













1 Answer
1






active

oldest

votes


















1
















You can achieve it using one of these solutions:



1) save the component reference in the chart object like that:



componentDidMount() 
this.chart = this.refs.chart.chart;
this.chart.component = this;



And use it inside mouseOver callback:



plotOptions: 
series:
point:
events:
mouseOver: function()
const self = this.series.chart.component;
const point =
x: this.x,
y: this.y
;

self.handleMouseOver(point);







Demo:



  • https://codesandbox.io/s/k0o59ljpnr





2) use IIFE to save the reference to the component object and then use it inside mouseOver callback function:



plotOptions: 
series:
point:
events:
mouseOver: (function(self)
return function()
const point =
x: this.x,
y: this.y
;
self.handleMouseOver(point);
;
)(this)






Demo:



  • https://codesandbox.io/s/y0x02o26pz





share|improve this answer

























  • Can the same pattern be followed for on click event instead of mouseover??

    – bubble-cord
    2 days ago











  • Yes, the same pattern can be used for a click event.

    – Wojciech Chmiel
    12 hours ago










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392659%2fhow-can-i-pass-values-from-highcharts-event-callbacks-click-mouseover-mouseou%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1
















You can achieve it using one of these solutions:



1) save the component reference in the chart object like that:



componentDidMount() 
this.chart = this.refs.chart.chart;
this.chart.component = this;



And use it inside mouseOver callback:



plotOptions: 
series:
point:
events:
mouseOver: function()
const self = this.series.chart.component;
const point =
x: this.x,
y: this.y
;

self.handleMouseOver(point);







Demo:



  • https://codesandbox.io/s/k0o59ljpnr





2) use IIFE to save the reference to the component object and then use it inside mouseOver callback function:



plotOptions: 
series:
point:
events:
mouseOver: (function(self)
return function()
const point =
x: this.x,
y: this.y
;
self.handleMouseOver(point);
;
)(this)






Demo:



  • https://codesandbox.io/s/y0x02o26pz





share|improve this answer

























  • Can the same pattern be followed for on click event instead of mouseover??

    – bubble-cord
    2 days ago











  • Yes, the same pattern can be used for a click event.

    – Wojciech Chmiel
    12 hours ago















1
















You can achieve it using one of these solutions:



1) save the component reference in the chart object like that:



componentDidMount() 
this.chart = this.refs.chart.chart;
this.chart.component = this;



And use it inside mouseOver callback:



plotOptions: 
series:
point:
events:
mouseOver: function()
const self = this.series.chart.component;
const point =
x: this.x,
y: this.y
;

self.handleMouseOver(point);







Demo:



  • https://codesandbox.io/s/k0o59ljpnr





2) use IIFE to save the reference to the component object and then use it inside mouseOver callback function:



plotOptions: 
series:
point:
events:
mouseOver: (function(self)
return function()
const point =
x: this.x,
y: this.y
;
self.handleMouseOver(point);
;
)(this)






Demo:



  • https://codesandbox.io/s/y0x02o26pz





share|improve this answer

























  • Can the same pattern be followed for on click event instead of mouseover??

    – bubble-cord
    2 days ago











  • Yes, the same pattern can be used for a click event.

    – Wojciech Chmiel
    12 hours ago













1














1










1









You can achieve it using one of these solutions:



1) save the component reference in the chart object like that:



componentDidMount() 
this.chart = this.refs.chart.chart;
this.chart.component = this;



And use it inside mouseOver callback:



plotOptions: 
series:
point:
events:
mouseOver: function()
const self = this.series.chart.component;
const point =
x: this.x,
y: this.y
;

self.handleMouseOver(point);







Demo:



  • https://codesandbox.io/s/k0o59ljpnr





2) use IIFE to save the reference to the component object and then use it inside mouseOver callback function:



plotOptions: 
series:
point:
events:
mouseOver: (function(self)
return function()
const point =
x: this.x,
y: this.y
;
self.handleMouseOver(point);
;
)(this)






Demo:



  • https://codesandbox.io/s/y0x02o26pz





share|improve this answer













You can achieve it using one of these solutions:



1) save the component reference in the chart object like that:



componentDidMount() 
this.chart = this.refs.chart.chart;
this.chart.component = this;



And use it inside mouseOver callback:



plotOptions: 
series:
point:
events:
mouseOver: function()
const self = this.series.chart.component;
const point =
x: this.x,
y: this.y
;

self.handleMouseOver(point);







Demo:



  • https://codesandbox.io/s/k0o59ljpnr





2) use IIFE to save the reference to the component object and then use it inside mouseOver callback function:



plotOptions: 
series:
point:
events:
mouseOver: (function(self)
return function()
const point =
x: this.x,
y: this.y
;
self.handleMouseOver(point);
;
)(this)






Demo:



  • https://codesandbox.io/s/y0x02o26pz






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 13:45









Wojciech ChmielWojciech Chmiel

4,8661 gold badge3 silver badges13 bronze badges




4,8661 gold badge3 silver badges13 bronze badges















  • Can the same pattern be followed for on click event instead of mouseover??

    – bubble-cord
    2 days ago











  • Yes, the same pattern can be used for a click event.

    – Wojciech Chmiel
    12 hours ago

















  • Can the same pattern be followed for on click event instead of mouseover??

    – bubble-cord
    2 days ago











  • Yes, the same pattern can be used for a click event.

    – Wojciech Chmiel
    12 hours ago
















Can the same pattern be followed for on click event instead of mouseover??

– bubble-cord
2 days ago





Can the same pattern be followed for on click event instead of mouseover??

– bubble-cord
2 days ago













Yes, the same pattern can be used for a click event.

– Wojciech Chmiel
12 hours ago





Yes, the same pattern can be used for a click event.

– Wojciech Chmiel
12 hours ago








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392659%2fhow-can-i-pass-values-from-highcharts-event-callbacks-click-mouseover-mouseou%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?