I have a series of line graph plotted with highcharts and the tooltip is shared among them.
http://jsfiddle.net/FhF3A/
$('#container').highcharts({
tooltip: {
shared: true
},
series: [{
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
});
What should be the best way to capture the dblclick event and obtain the hover y axis value on the graph ?
This is explained fairly well in the documentation.
What you can do is something similar to THIS.
So you have to add something like this to your code:
chart: {
events: {
click: function(event) {
alert (
'x: '+ Highcharts.dateFormat('%Y-%m-%d', event.xAxis[0].value) +', ' +
'y: '+ event.yAxis[0].value
);
}
}
}
Here is an example of that implementation.
Update
To ensure clicking on the graph itself is also enabled, add the following:
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function() {
alert ('Category: '+ this.category +', value: '+ this.y);
}
}
}
}
},
You can see a working example HERE
if you want to do a single click to a line, you can do so by setting plotOptions > line as in http://api.highcharts.com/highcharts#plotOptions.line.events.click.
Now if you want a double click you may have a global variable, which keep track of number of clicks within the same click event.
hope helps
Related
I have one chart and i want to include hover on area but i found it works only on point only.
series: [{
name: 'Target',
type: 'polygon',
data: [[153, 42], [149, 46], [149, 55], [152, 60]],
color: Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.5).get(),
enableMouseTracking: true
}],
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
http://jsfiddle.net/onhfLqdm/3/
As area is bounded by points so how can i hover area instead of points?
Update On hover on each polygon asker wants to show data coming from json.To do so in a div out of container please view this fiddle
In Tooltip One more option to show some info coming from json ,tooltip can be used.Put your data using some name like "someText" (as in my fiddle )and get it in formatter function of tooltip using
this.options.someText
See this fiddle for data in tooltiip
Old Answer:
plotOptions: {
series: {
events: {
mouseOver: function () {
$("#polygon").html('Moused over Event')
.css('color', 'green');
},
mouseOut: function () {
$("#polygon").html('Moused out Event')
.css('color', 'red');
}
}
}
}
Fiddle link is here
I'm building a graph using Highcharts-3d v.4.1.4 and a click does not work - plotOptions.scatter.point.events.click. I use IE8.0.7601.17514 and jQuery 1.11.0. Chart works perfectly fine in chrome and ie11.
As example I take this:
plotOptions: {
scatter: {
width: 10,
height: 10,
depth: 10,
point:{
events:{
click: function(event){
alert('hello');
}
}
}
}
},
The problem is related with general issue in IE8/9 with click event.
Related topic: https://github.com/highslide-software/highcharts.com/issues/4045
I did so:
chart = new Highcharts.Chart({
chart: {
renderTo: 'first_graph',
type: 'scatter',
backgroundColor: '#fdfdfd',
height:800,
events:{
click: function(event){
if (this.hoverPoint!=null){
alert('Hi!');
}
}
}
I have an issue where I want to change the fill color of a column series when hovering another series. (This is to visualize related series)
I succeeded in changing the color on mouseOver, but I'm not able to restore the color on mouseOut.
The code I have until now is on jsFiddle
var hoverSerie;
var originalColor;
var newColor = '#a760d6'
$(function () {
var t = $('#container').highcharts({
chart: {
type: 'column'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0
},
plotOptions: {
column: {
stacking: 'normal'
}
},
series:[{
events: {
mouseOver: function() {
hoverSeries = this.chart.series[2]
originalColor = hoverSeries.options.color;
hoverSeries.options.color = newColor;
hoverSeries.update(hoverSeries.options);
},
mouseOut: function(){
if(originalColor)
{
hoverSeries.options.color = originalColor;
hoverSeries.update();
}
}
},
animation : false,
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
animation : false,
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
animation : false,
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
});
When hovering (mouseOver) the top stacked series (light blue) the color of the bottom (black) series. For one or other reason, the mouse out event is working differently as the mousOver event. The code appears to loop when doing a mouseOut.
Apparently when doing update inside mouseOut the redraw-part of the update causes mouseOut to be called recursively, eventually leading to "stack size exceeded". In this updated Fiddle I've used a boolean to prevent it from happening recursively, which seems to be working for me in Chrome. Hope it it what you were looking for. The only real change is the addition of the mouseWasOver variable used in both mouseOver and mouseOut.
This appears to be a bug(?) related to calling update inside mouseOut that was reported as early as 2011 on their GitHub, and 2010 on their forum.
I have a problem with click events on heatmaps: it works only if you click on a tooltip, but not on the chart itself. See the demo http://jsfiddle.net/3UWaA/1/
chart: {
type: 'heatmap',
events: {
click: function(event) {
alert("clicked!");
}
}
}
Any suggestions how to fix this?
Thanks
Add the events into a plotOptions object.
Like this:
plotOptions: {
series: {
events: {
click: function (event) {
alert('event!');
}
}
}
},
Demo: http://jsfiddle.net/robschmuecker/3UWaA/3/
Because click event on chart, works in the plotArea, not on the serie. Heatmap serie overlap plotArea, so click event doesnt work. You need to catch plotOptions event on serie / point.
Try inserting the EVENTS: under series block and disable the tooltip as below:
series:
[
{ name: 'Passed',
borderWidth: '1',
borderColor: '#000000',
cursor: 'pointer',
events:
{
click: function ()
{
alert('wow');
}
},
color:'green',
data: [[0, 1, ''],[0, 2, ''],[0, 3, '']],
dataLabels:
{
enabled: 'true',
color: '#000000'
}
}
]
So when you click the chart itself,click event will work fine.
I need to disable the hover attribute of legend items because I am using Highcharts on mobile platforms. Sadly, making a legendItemClick event does not solve the problem as hovering still occurs.
I was encouraged to see that this issue came up on the old support site for highcharts back in 2011. The thread can be found here. I was particularly glad to see the last jfiddle example and the function declared in it.
Unfortunately, the only thing that worked for me was the workaround of changing the setHoverStyle to null. This isn't great though since the hover action still fires and makes navigating the legend and chart unresponsive. The rest of the suggestions in the above thread resulted in the chart not being rendered.
Granted, it might be because I had a difficult time translating the example to my purposes - honestly, I do not know where to call the function and everywhere I have tried has failed. My JavaScript file is set up along the lines of
var chartDefinition = {
chart: {
renderTo: 'chart_content',
type: 'column'
},
colors: [
'#619ED6',
'#6BA547',
'#F7D027',
'#E48F1B',
'#B77EA3',
'#E64345',
'#60CEED',
'#9CF168',
'#F7EA4A',
'#FBC543',
'#FFC9ED',
'#E6696E'
],
title: {
text: ''
},
...
column: {
shadow: false,
borderWidth: 1,
events: {
click: function() { return false; },
legendItemClick: function() { return false; }
},
dataLabels: {
enabled: false,
color: '#222',
style: {
fontFamily: 'sans-serif',
fontSize: '13px',
fontWeight: 'bold'
}
}
}
},
series: []
};
Listing and setting the various highcharts attributes.
Does anyone know how to disable this hover attribute or where the proper place would be to call the function?
There are a few solutions to implement this. There's no built-in option to change that (as of 06.2022).
Try to disable mouseover for legendGroup, not legendItem.
Demo: http://jsfiddle.net/Cp7xh/10/
Disable pointer-events in CSS:
.highcharts-legend {
pointer-events: none;
}
Demo: http://jsfiddle.net/BlackLabel/ebrodhk4/
A plugin that prevents Highcharts Core from adding events:
Plugin:
(function(H) {
H.wrap(
H.Legend.prototype,
'init',
function(proceed, chart, options) {
if (options.enableMouseTracking === false) {
this.setItemEvents = false;
}
proceed.apply(this, [chart, options]);
}
);
})(Highcharts);
Usage:
legend: {
enableMouseTracking: false,
itemStyle: {
cursor: 'auto'
}
},
Demo: https://jsfiddle.net/BlackLabel/ogqv2sya/