我在我的图表中使用nvd3 boxplot。在箱线图上有mean
作为星号(*)的选项吗?我们是否也可以在顶部晶须上方具有n
值,类似于下图。
此问题已发布here。 提前谢谢。
修改 我想添加一个我从数据点计算的平均值,而不仅仅是盒子图的中心。由于异常值,计算出的平均值可能不在箱形图的中心。
答案 0 :(得分:2)
您可以通过执行以下算法来实现此目的:
代码段:
function makeMarkOnMean(){
d3.selectAll(".mean").remove();//remove all * mean markers
//get all the rectangles
d3.selectAll(".nv-boxplot-box")[0].forEach(function(r){
window.setTimeout(function(){
var x = parseFloat(d3.select(r).attr("x")) + d3.select(r).attr("width")/2 - 3; //x position of the star
var y = parseFloat(d3.select(r).attr("y")) + parseFloat(d3.select(r).attr("height"))/2+12;//y position of the star
//now make the star on the above x and y
d3.select(r.parentNode).append("text").attr("class", "mean").style("font-size", "x-large").text("*").style("fill", "red").attr("x",x).attr("y", y);
},500)
});
工作代码here。