繁体   English   中英

在直方图上画一条线-d3

[英]drawing a line on a histogram - d3

我已经使用d3创建了一个直方图。

一切都很好,这就是我被困住的地方。

我想在一些值上画一条垂直线。

认为我想画一条与某些值相对应的线。 假设180。

我尝试了,尝试了并且仍然尝试着我找不到办法。

这是小提琴

有人请帮我画一条与某些特定值相对应的线。

如果有人想知道如何绘制垂直线,下面是有关如何绘制垂直线的代码。 从OP提供的Fiddle中编辑。

var svg = d3.select(reference).append("svg")
    .attr("width", width)
    .attr("height", height + 20);
// to draw lines at x=6 and x=500
svg.append("g").selectAll("line")
    .data([
        { y1: y(0), y2: height, x1: 6, x2: 6 },
        { y1: y(0), y2: height, x1: 500, x2: 500 }
    ])
    .enter().append("line")
    .attr("class", "specification-line")
    .attr("y1", function (d) { return d.y1; })
    .attr("y2", function (d) { return d.y2; })
    .attr("x1", function (d) { return d.x1; })
    .attr("x2", function (d) { return d.x2; });

用虚线和红色线条造型

.specification-line { fill:none; stroke: #ff0000; stroke-opacity: .6; stroke-width: 1px; shape-rendering: auto; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM