Is it possible to have tool tip on clicking of points instead of mouse move.
I have tried with showing values in java script alert as below
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function() {
alert ('Category: '+ this.category +', value: '+ this.y);
}
}
}
}
}
Requirement is to show high chart tool tip on click.
Please help. Thanks!
As #PawelFus states, it's not officially supported but you can fudge this in by taking control of the visiblity of the tooltip.
First on chart load, hide it:
chart: {
events: {
load: function(){
$('.highcharts-tooltip').hide();
}
}
},
Disable sticky tracking, and on mouseout hide it, on click show it:
plotOptions: {
series: {
stickyTracking: false,
events: {
click: function() {
$('.highcharts-tooltip').show();
},
mouseOut: function() {
$('.highcharts-tooltip').hide();
}
}
}
},
Here's a fiddle example.
First attempt only worked in chrome, here's another:
Disable the default tooltip:
tooltip: {
enabled: false
},
In the chart load event, create your own:
chart: {
events: {
load: function(){
this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip);
}
}
},
In the click and mouseout control it:
plotOptions: {
series: {
stickyTracking: false,
events: {
click: function(evt) {
this.chart.myTooltip.refresh(evt.point, evt);
},
mouseOut: function() {
this.chart.myTooltip.hide();
}
}
}
},
I tested this in IE and Chrome, I won't install Firefox anymore.
Update to code 9/7/2017 with new stack snippet:
$(function () {
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
tooltip: {
valueSuffix: '°C',
enabled: false
},
chart: {
events: {
load: function(){
this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip);
}
}
},
plotOptions: {
series: {
stickyTracking: false,
events: {
click: function(evt) {
this.chart.myTooltip.options.enabled = true;
this.chart.myTooltip.refresh(evt.point, evt);
},
mouseOut: function() {
this.chart.myTooltip.hide();
this.chart.myTooltip.options.enabled = false;
}
}
}
},
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.src.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Adding for those who have problems like me with useHTML: true and wants to display tooltip only on click and not on hover.
tooltip: {
useHTML: true
}
Here is a fiddle.
Just add for those who has the same problems as myself (see comment from #kevinandrada just after correct answer, i can't comment): if you call tooltip.refresh when your tooltip.shared = true you'll get an exception Uncaught TypeError: Cannot read property 'category' of undefined.
You should provide an array of points as a first argument:
plotOptions: {
series: {
stickyTracking: false,
events: {
click: function(evt) {
var points = this.chart.series.map(function(d) {
return d.searchPoint(evt, true)
});
this.chart.myTooltip.refresh(points, evt);
},
mouseOut: function() {
this.chart.myTooltip.hide();
}
}
}
},
The problem of first mouse-over tooltip showing in Alexandra Espichán excellent fiddle can be solved via css and the mouseover event omit by replacing his invisibility class with:
.highcharts-tooltip:not(.clone){
visibility: hidden !important;
}
Here is the fix for "Cannot read category of undefined". I just take hovered points of chart and pass them to refresh.
point: {
events: {
mouseOver: function(evt) {
var hoveredPoints = a.hoverPoints;
a.tooltip.refresh(hoveredPoints);
},
mouseOut: function() {
a.tooltip.hide();
}
}
}
Sample fiddle here: http://jsfiddle.net/2swEQ/153/
Related
I've created a column chart that you can drill into. The problem is that there are many columns of data when you drill. How do I keep the widths and overall size of the drilled data the same as the main chart and make the plot region scrollable instead?
As you can see I've tried making the the div containing the chart a max width, hoping that would force and overflow...but not such luck.
<body>
<div class="container-fluid">
<div class="row">
<div id="ctReferrals" style="max-width: 500px; overflow-x: auto"></div>
</div>
</div>
</form>
</body>
function loadChart() {
refChart = new Highcharts.chart('ctReferrals', {
chart: {
type: 'column',
backgroundColor: 'whiteSmoke',
},
title: {
text: 'Total # of Referrals by School Level'
},
subtitle: {
text: 'By Year'
},
xAxis: {
categories: categoriesSL,
},
yAxis: [{
title: {
useHtml: true,
text: '<strong># Referrals</strong>'
}
}],
plotOptions: {
column: {
borderRadius: 5,
cursor: 'pointer',
dataLabels: {
enabled: true,
},
point: {
events: {
click: function () {
var schoolLevel = this.schoolLevel;
var schoolID_alt = this.schoolID_alt;
if (schoolID_alt == 0) { // drill down
if (schoolLevel == "01")
setChart(categoriesElem, [pyElem, cyElem]);
else if (schoolLevel == "02")
setChart(categoriesMid, [pyMid, cyMid]);
else if (schoolLevel == "03")
setChart(categoriesHigh, [pyHigh, cyHigh]);
} else { // restore
setChart(categoriesSL, [pySL, cySL]);
}
}
}
},
}
},
series: [{
name: dataLabels[0],
data: pySL
}, {
name: dataLabels[1],
data: cySL
}],
credits: {
enabled: false
}
})
}
You can set min and max properties for xAxis and toggle scrollbar from Highstock on drill-events:
chart: {
events: {
drilldown: function() {
this.update({
scrollbar: {
enabled: true
}
}, false);
},
drillupall: function() {
this.update({
scrollbar: {
enabled: false
}
}, false);
}
}
},
xAxis: {
min: 0,
max: 2
}
Live demo: http://jsfiddle.net/BlackLabel/xtg5Lu20/
API: https://api.highcharts.com/highcharts/chart.events
I am using Pie Highchart, I want to call a function on click event. I don't want to write this function logic as below. Is it possible to call a external function here.
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true,
point:{
events:{
click: function(oEvent){
alert(oEvent.point.name);
}
}
}
}
},
This call back function will have many lines of code, so I want to define it somewhere else and call it in plotoptions. Let me know, how to achieve it
It done following way
Fiddle
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
},
point: {
events: {
click: function(oEvent) {
callExternalFunction(oEvent.point.name); //call function with arguments
}
}
}
}
},
function callExternalFunction(obj){
console.log(obj);
}
Heading ##I have done it by using this way
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: this.barClickedFun.bind(this)
}
}
}
Outside function:-
barClickedFun(data) {
console.log(data.point.index);//data of click event, One can found point's value or index
}
I´m trying to display a timeline using Highchart, my problem is that when you put the mouse over one element of the series, it highlight and shows the tool-tip of other element of the same series. What I´m doing wrong?
You can see a http://jsfiddle.net/ncdysafk/
var chart;
var options = {
chart: {
events: {
load: function(){
this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip);
}
},
renderTo: 'container',
type: 'columnrange',
inverted: true,
zoomType: 'y'
},
title: {
text: 'Portes de hoy'
},
xAxis: {
categories: ["SERIE1","SERIE2","SERIE3"]
},
yAxis: {
type: 'datetime',
title: {
text: 'Horas del día'
}
},
plotOptions: {
series: {
stickyTracking: true,
events: {
click: function(evt) {
this.chart.myTooltip.refresh(evt.point, evt);
},
mouseOut: function() {
this.chart.myTooltip.hide();
}
}
},
columnrange: {
grouping: false
}
},
legend: {
enabled: true
},
series: [{"name":"SERIE2","data":[{"x":1,"low":1425538800000,"high":1425543300000},{"x":1,"low":1425567600000,"high":1425571200000},{"x":1,"low":1425584000000,"high":1425589100000}]},{"name":"SERIE3","data":[{"x":2,"low":1425538800000,"high":1425543300000},{"x":2,"low":1425567600000,"high":1425571200000}]}]
};
chart = new Highcharts.Chart(options);
This is bug in 4.1.3/2.1.3 version of Highcharts/Highstock. Bug reported is here. Already fixed, that means try https://github.highcharts.com/highstock.js and https://github.highcharts.com/highcharts-more.js files from master branch. Working demo http://jsfiddle.net/ncdysafk/1/
I'm working with Highchart. I've got a multiple series graph in which several series can be associated to the same y-axis. The association is based on the measurement unit, which is also the y-axis id. Series are added dynamically.
Each y-axis has setExtremes() different than null and for this reason I have encountered one problems that it seems I can't resolve.
When hiding a series. I want the associative y-axis to be visible until all the series associated to that specific axis are hidden also. At the moment I was able just to hide the y-axis once one of the series is set to series.hide()
The used code is presented below. And can be accessed in jsfiddle through this like: http://jsfiddle.net/39xBU/134/ .
$(function () {
//creates chart options
var options = {
chart: {
renderTo: 'container',
zoomType: 'xy'
},
title: {
text: 'Axis manipulation'
},
xAxis: [{
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
}],
yAxis: [{ // Primary yAxis
id:'°C',
labels: {
formatter: function() {
return this.value +'°C';
},
style: {
color: '#89A54E'
}
},
title:{
text:''
},
opposite: true,
showEmpty: false
}, { // Secondary yAxis
id:'mm',
gridLineWidth: 0,
labels: {
formatter: function() {
return this.value +' mm';
},
style: {
color: '#4572A7'
}
},
title:{
text:''
},
showEmpty: false
}],
tooltip: {
formatter: function() {
var unit = {
'Rainfall': 'mm',
'Temperature': '°C',
'Sea-Level Pressure': 'mb'
}[this.series.name];
return ''+
this.x +': '+ this.y +' '+ unit;
}
},
legend: {
layout: 'vertical',
align: 'left',
x: 120,
verticalAlign: 'top',
y: 80,
floating: true,
backgroundColor: '#FFFFFF'
},
series: []
};
// Adds series to the chart. i do this because in the real application I add data dinamically
options.series.push({
name: 'Rainfall',
color: '#4572A7',
type: 'spline',
yAxis: getAssociativeYAxisIndex('mm', options.yAxis),
data: [149.9, 171.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 195.6, 154.4]
});
options.series.push({
name: 'Sea-Level Pressure',
type: 'spline',
color: '#4572A7',
yAxis: getAssociativeYAxisIndex('mm', options.yAxis),
data: [116, 116, 115.9, 115.5, 112.3, 109.5, 109.6, 110.2, 113.1, 116.9, 118.2, 116.7],
marker: {
enabled: false
},
dashStyle: 'shortdot'
});
options.series.push({
name: 'Temperature',
color: '#89A54E',
type: 'column', // date is not shown only if it is 'spline'
yAxis:getAssociativeYAxisIndex('°C', options.yAxis),
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
});
var chart = new Highcharts.Chart(options);
//after rendering I set axis limits, based on their measurement unit.
var yAxis1 = chart.get('mm');
yAxis1.setExtremes(0, 200);
var yAxis2 = chart.get('°C');
yAxis2.setExtremes(0, 40);
// hide Rainfall button
$("#b1").click(function(){
chart.series[0].hide()
chart.yAxis[1].update({
labels: {
enabled: false
},
title: {
text: null
}
});
});
// hide sealevel button
$("#b").click(function(){
chart.series[1].hide()
chart.yAxis[1].update({
labels: {
enabled: false
},
title: {
text: null
}
});
});
// delete rainfall button
$("#b2").click(function(){
chart.series[0].remove();
chart.yAxis[1].setExtremes(null, null);
});
// delete sea-level button
$("#b3").click(function(){
chart.series[1].remove();
chart.yAxis[1].setExtremes(null, null);
});
//get's series associatie axis
function getAssociativeYAxisIndex(seriesMeasureUnit, yAxis) {
var axisIndex = -1;
$.each(yAxis, function (index, axes) {
if (seriesMeasureUnit == axes.id) {
axisIndex = index;
return false;
}
});
return axisIndex;
};
});
Any suggestions to this matter would be very useful.
You can simply check if all of series are hidden, this way: http://jsfiddle.net/39xBU/135/
And code:
new function to make it easy to read:
function hideShowAxis(series) {
var axis = series.yAxis,
show = false;
$.each(axis.series, function (i, e) {
if (e.visible) {
show = true;
}
});
axis.update({
labels: {
enabled: show
}
});
}
and execute:
// hide Rainfall button
$("#b1").click(function () {
chart.series[0].hide()
hideShowAxis(chart.series[0]);
});
// hide sealevel button
$("#b").click(function () {
chart.series[1].hide()
hideShowAxis(chart.series[1]);
});
HI all i am some data in a pie chart...on hover of slice i get the hover like this
[Hr Resources:x=Hr Resources,y=12]
i want my tooltip to show like this
[ProjectName=Hr,Logged Bugs=12]
how do i do this..here is how i am binding my data to the pie chart
<script type="text/javascript">
$(function () {
$.getJSON('<%= Url.Action("GetData","JqueryCharts") %>', {}, function (data) {
var json = data;
alert(json);
var jsondata = [];
for (var i in json) {
// var serie = new Array(json[i].Projects, json[i].Bugs);
jsondata.push([json[i].Projects, json[i].Bugs]);
}
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'pie',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Resource Reports of BugTracker'
},
plotOptions: {
pie: {
showInLegend: true,
animation: false,
allowPointSelect: true,
cursor: 'pointer'
}
},
legend: {
enabled: true
},
series: [{
type: 'pie',
name: 'Resource Reports',
data: jsondata
}]
});
});
});
</script>
can any one help where i have to change this
By default, Highchart tooltip picks up, series name in the tooltip.
You can customize tooltip using:
tooltip: {
formatter: function() {
return '<b>ProjectName = '+ this.point.name +', Logged Bugs= '+ this.y + '</b>';
}
}
Here is the example
Highchart has a very good documentation at :http://api.highcharts.com/highcharts#tooltip