gpt4 book ai didi

javascript - 在直方图上画一条线 - d3

转载 作者:行者123 更新时间:2023-11-28 08:22:11 24 4
gpt4 key购买 nike

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

一切都很好,这就是我陷入困境的地方。

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

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

我尝试了,尝试了,仍然在尝试,但我想不出办法。

这是Fiddle .

请有人帮我画一条对应于某个特定值的线。

最佳答案

如果有人有兴趣知道如何绘制垂直线,下面是如何绘制垂直线的代码。根据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; }

关于javascript - 在直方图上画一条线 - d3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22831098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com