【发布时间】:2019-10-30 00:21:15
【问题描述】:
我正在尝试使用 D3.js 创建赛车条形图。我对图书馆很陌生,所以我尝试修改this example 以了解图书馆的工作原理。
很遗憾,我收到以下错误:TypeError: svg.append(...).attrs is not a function.
这是我的代码:
<script>
tickDuration = 300;
top_n = 20;
height = 768;
width = 1366;
(function(){
const svg = d3
.select("body")
.append("svg")
.attr("width", 1366)
.attr("height", 768);
const margin = {
top: 80,
right: 0,
bottom: 5,
left: 0
};
let barPadding = (height-(margin.bottom+margin.top))/(top_n*5);
let title = svg.append('text')
.attrs({
class: 'title',
y: 24
})
.html('18 years of Interbrand’s Top Global Brands');
// More code but the above lines are causing the error.
如何更正上面的代码?
【问题讨论】:
标签: javascript d3.js svg bar-chart