Highcharts: how display tooltip, when point = null? -
when hover on may in example, don't see tooltip
month, because data null. can set settings see tooltip when data null?
well far know there no generic option since highcharts ignores null values showing.
on other hand, can replace null
points "fake" ones, have average value between 2 closest points (this cause chart flow remain same), , custom property isnull
can used flag later.
after doing that, can use formatter
function tooltip, , manipulate tooltip way want, example displaying series name when point isnull
.
$(function () { $('#container').highcharts({ title: { text: 'the line connected april juni, despite null value in may' }, xaxis: { categories: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] }, plotoptions: { series: { connectnulls: true } }, tooltip: { formatter: function(){ if(this.point.isnull == undefined) return this.series.name+"<br>"+"<b>value:</b>"+this.y; return this.series.name; } }, series: [{ data: [null, 71.5, 106.4, 129.2, null, 176.0, 135.6, null, 216.4, 194.1, 95.6, 54.4] }] }, function(chart){ var series = chart.series[0]; var data = series.data; $.each(data,function(i){ var point = data[i]; var prevpoint = data[i-1] != undefined ? data[i-1].y : 0; var nextpoint = data[i+1] != undefined ? data[i+1].y : 0; if(point.y == null){ series.addpoint({x:point.x,y:(prevpoint+nextpoint)/2, isnull:true}); } }); }); });
http://jsfiddle.net/zb5ksxtc/1/
i hope meant.
update can not less hacky... (i guess little hacking work fine in unusuall case)
what did here creating "fake" scatter series, points located null values real series (used same average logic). series has hidden markers, , has unique name.
after that, used shared
tooltip , formatter
display right tooltip. used name
attribute determine series focused:
$(function () { $('#container').highcharts({ title: { text: 'the line connected april juni, despite null value in may' }, xaxis: { categories: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] }, plotoptions: { series: { connectnulls: true, }, }, tooltip: { shared:true, formatter: function(){ var points = this.points; var seriesname = points[0].series.name; if(seriesname == 'fake') return "null tooltip"; return seriesname+"<br>value: <b>"+this.y+"</b>"; } }, series: [{ type:'areaspline', data: [null, 71.5, 106.4, 129.2, null, 176.0, 135.6, null, 216.4, 194.1, 95.6, 54.4] }, { type:'spline', linewidth:0, name:'fake', showinlegend:false, marker:{ symbol:'circle', radius:0, } } ] }, function(chart){ var series = chart.series[0]; var fake_series = chart.series[1]; $.each(series.data, function(i){ var point = this; var nextpoint = series.data[i+1] != undefined ? series.data[i+1].y : 0; var prevpoint = series.data[i-1] != undefined ? series.data[i-1].y : 0; if(series.data[i].y == null) fake_series.addpoint([series.data[i].x, (nextpoint+prevpoint)/2]); }); }); });
and fiddle ofcourse: http://jsfiddle.net/zb5ksxtc/8/
Comments
Post a Comment