【发布时间】:2019-12-24 14:33:56
【问题描述】:
图例是在g 标记中创建的。我怎样才能像这个例子一样把它拉出来。
右侧有颜色条。
代码
this.svg = d3.select("#airlineChart").select("svg");
this.mainContainer = this.svg
.append("g")
.attr("transform", `translate(${this.radius},${this.radius})`)
;
private drawSlices() {
this.slices = this.mainContainer
.selectAll("path")
.remove()
.exit()
.data(this.pie(this.pieairline))
.enter()
.append("g")
.append("path")
.attr("d", this.arc);
this.slices
.append("rect") // make a matching color rect
.attr("class", "pieLegend")
.attr("width", 10)
.attr("height", 10)
.append("text") // add the text
.text(function(d) {
return d.data.name;
})
.style("font-size", 12)
.attr("y", 10)
.attr("x", 11);
this.slices
.attr("fill", (d, i) => this.color(i))
.attr("stroke", "black")
.style("stroke-width", "0px");
}
slice 只是带有任何datatype 的计划变量
当前视图
控制台
【问题讨论】:
-
我们需要更多代码。你能告诉我们,
this.slices是在哪里定义的吗? -
@Sirko,问题已更新。