angularjs - 如何在 D3.js 的折线图中的图例中添加带有 Eclipse 的工具提示
问题描述
我想在 D3.js 的折线图中的图例中添加带有工具提示的 Eclipse
我在这里附加了我的工作 JSFiddle 和 Legend
var legend = svg.append("g")
.attr("class", "legend")
.attr("height", 100)
.attr("width", 100).attr('transform', 'translate(-20,0)');
`
如果图例名称太长,则无法使用工具提示设置 Eclipse
我在这里搜索,但我在 Legend 中找到了自动换行的所有示例,所以请帮助我使用工具提示设置 Eclipse。
解决方案
您需要使用子字符串来显示几个图例字符,然后附加一个标题。如下所示。我修改了你的图例文本部分。
legend.selectAll('text')
.data((this.materialGraphDataSource[0].materials))
.enter()
.append("text")
.attr("x", width - 140)
.attr("y", function (d, i) { return i * 20 + 9; })
.text(function (d, i) {
var text = d.materialName;
return text.substring(0,20)+ "...";
})
.style("font-size", "10px")
.append('title').text(function (d, i) {
var text = d.materialName;
return text;
});
推荐阅读
- javascript - Vue.js 2 + Webpack,V-Model 从 router.params 绑定和加载数据,可选默认值不起作用
- java - 如何使用 ftpclient java 从 ftp 下载前 20 个文件
- javascript - 绘制并拖动线条的边缘
- css - 如何从角度弹出窗口中删除垂直滚动条
- java - 我用netty编写了一个应用程序,从客户端向服务器发送消息,但服务器无法接收到消息
- windows - 什么样的证书?如何摆脱它?
- javascript - WP & ACF:由于脚本队列而导致管理员运行时错误
- sql - 左连接到左连接
- reactjs - 如何在 Next.js 中使用 webrtc-adapter npm 包
- javascript - 运行 webpack-dev-server 时如何修复 Bootstrap 错误?