javascript - Display horizontal dashed lines between y axis values
问题描述
Need to show 10 dashed lines in each y axis like in below image.
[img]https://i.imgur.com/ZTRnP0o.jpg[/img]
My current output is like in below image. [img]https://i.imgur.com/AfuXZH4.jpg[/img]
I'm using d3 chart v4 and my current working code attached.
HTML
<!DOCTYPE html>
<meta charset="utf-8">
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<!-- Create a div where the graph will take place -->
<div id="my_dataviz"></div>
CSS
.yAxis > .tick > text {
stroke: #4a4a4a;
shape-rendering: crispEdges;
font-size: 14px;
}
.yAxis > path {
stroke: #bebebe;
}
Javascript
var y = d3.scaleLinear()
.domain([0, d3.max(data, function (d) { return +d.Value; })])
.range([height, 0])
svg.append("g")
.attr("class", "yAxis")
.call(d3.axisLeft(y).tickPadding(5))
.selectAll("text")
.attr("x", 0)
.attr("y", -15)
.attr("dy", ".35em")
.attr("transform", "rotate(-90)")
.style("text-anchor", "middle");
d3.selectAll("g.yAxis g.tick")
.append("line")
.attr("class", "gridline")
.attr("x1", 0)
.attr("y1", 0)
.attr("x2", width)
.attr("y2", 0);
Sample code link - https://www.d3-graph-gallery.com/graph/line_several_group.html
解决方案
推荐阅读
- python - 是否有必要使 uqiue 索引列不可为空(SQL、SQLAlchemy)?
- r - 从特定行获取数据
- python - jinja2.exceptions.TemplateNotFound:index.html
- laravel - Laravel 6.8 返回 404 未找到页面
- swift - 使用滚动视图在 Xcode 11 中缩放图像,避免“不明确的内容大小”自动布局错误
- sql - 如果 2 列具有相同的数据 - Codeigniter,如何比较 SQL 中的两个表?
- python - 如何让电脑用python说话?
- android - 来自 React Native 的 Android App Bundle:您上传的 APK 或 Android App Bundle 的某些文件的签名信息无效或缺失
- android - 为什么我的底部导航视图不显示任何标题或图标?
- python-3.x - 以下 ResNet50 分类模型中验证准确度为 0 的原因