Forum > TAChart
Box-and-whisker plot with outliers
apeoperaio:
Hi,
Is it possible to add outliers to the box-and-whisker plot? (see https://en.wikipedia.org/wiki/Box_plot).
Outliers are represented as points above and below the whiskers.
Should I use two different series? A TBoxAndWhiskerSeries and a TLineSeries?
There are any example around?
Thank you!
wp:
I am afraid that it is not feasible to add outliers to the Box-and-Whisher series in TAChart. This is because in TAChart the chart-source which provides the data to the series must have a well-definded number of x and y values for all data points. In the Box-and-Whisker series there are 1 x value and 5 y values (whisker min, box min, box center, box max, whisker max). Outliers should be included in the same chart source. But since the number of outliers is not the same for all data points the source cannot have a pre-defined count of y values any more.
I'd recommend to put the outliers into a line series in which you turn on the pointer symbols and turn off the connecting lines. Give the outlier series the same color as the related box/whisker series to indicate that they belong together.
See a simple demo in the attachment.
apeoperaio:
Thank you for the prompt reply and for the demo. Very useful.
apeoperaio:
I encountered an unexpected behaviour related on how to add values to the box and whiskers plot.
In the project included in this thread the points are added using the dedicated method:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- ABoxAndWhiskerSeries.AddXY( AData[i].Date, AData[i].Min, AData[i].LowerQuartile, AData[i].Median, AData[i].UpperQuartile, AData[i].Max );
The previous code works properly (see image1.png), while the following code does not draw the box and whiskers plot properly (see image2.png):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].Min); ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].LowerQuartile); ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].Median); ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].UpperQuartile); ABoxAndWhiskerSeries.AddXY(AData[i].Date, AData[i].Max);
Why? Aren't the two code snippets equivalent? Am I doing something wrong?
I am using:
Lazarus 4.4 (rev lazarus_4_4) FPC 3.2.2 aarch64-darwin-cocoa
wp:
TBoxAndWhiskerSeries is a multi-valued series which requires all y values per data point at once. Doing this in "steps" like you are proposing, adds each time a new data point with the same x value and a single y value.
Navigation
[0] Message Index
[#] Next page