Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Hover on boxplot: get information which is median,q1,q3

Hi and thanks again for plotly.js:-)
Currently I try to draw boxplots.
I want to make my own tooltip. How I can get the Information of the points in hoverFunc, which point is what? So which point is e.g. the median? Or q1, q3?

hoverFunc=function(data){
   //get dataobject for tooltip
   var measurePoints=[];
   data.points.forEach(function(p) {
        console.log(p.data.name+"= x:" + p.x +"; y:" + p.y);
        //what is median, q1, q3, whiskers, outliers?
   });	
};

btw: I would also like to supply my own precomputed statistic (median,q1,q3) to a boxplot:-)

Here’s how: http://codepen.io/etpinard/pen/RorRvO

1 Like

Thank you very much for your answer:-) The only thing I don’t understand is the outliers part. Why the result in your example is “-5.75 - 10”? Where the value -5.75 comes from or what means calcPt.lo?

To let work the code for BoxPlot series (e.g. one BoxPlot per month) the following code should work:

var chartDivId = "myDiv";
hoverFunc=function(data){
   //get dataobject for tooltip
   var measurePoints=[];
   var chartDiv = document.getElementById(chartDivId);
   var calcData = chartDiv.calcdata;
   var p = data.points[0];
	//what is median, q1, q3, whiskers, outliers?
	var calcPt = calcData[p.curveNumber][p.pointNumber];
	var median = calcPt.med;
	var q1 = calcPt.q1;
	var q3 = calcPt.q3;
	var whiskers = calcPt.lf +" - " + calcPt.uf;
	var outliers = calcPt.lo +" - " + calcPt.uo;
		
	//other values in calcPt: max, min, mean, pos, sd
};

calcData contains for each y-value (e.g. each month) one statistic object (calcPt). But calcData is indexed from e.g. from 0-11. To get the right statistic object you can use the p.pointNumber. I think no loop is needed over the points cause we only need the pointNumber one times.

Hi,
I still have the problem with outliers in calcdata and think it’s a bug. I have the problem by using boxplots… the example is that what @etienne give: http://codepen.io/etpinard/pen/RorRvO11

Can anybody help me? Why there comes -5.75 - 10 for outliers