Angular D3角度图表轴标签

Angular D3角度图表轴标签,angular,d3.js,Angular,D3.js,我这里有一个失物招领- 我想这是D3拼图的最后一块 如何将标签添加到轴 private drawAxis() { this.g.append("g") .attr("class", "axis axis--x") .attr("transform", "translate(0," + this.height + ")") .call(d3.axisBottom(this.x)) .classed('x axis', true

我这里有一个失物招领-

我想这是D3拼图的最后一块

如何将标签添加到轴

private drawAxis() {
    this.g.append("g")
        .attr("class", "axis axis--x")
        .attr("transform", "translate(0," + this.height + ")")
        .call(d3.axisBottom(this.x))
        .classed('x axis', true)
        .call(this.x)
        .append('text')
        .attr("transform",
            "translate(" + (this.width/2) + " ," +
            (this.height + this.margin.top + 20) + ")")
        .style("text-anchor", "middle")
        .text("Letters");
    this.g.append("g")
        .attr("class", "axis axis--y")
        .call(d3.axisLeft(this.y).ticks(10, "%"))
        .append("text")
        .attr("class", "axis-title")
        .attr("transform", "rotate(-90)")
        .attr("y", 6)
        .attr("dy", "0.71em")
        .attr("text-anchor", "end")
        .text("Frequency");
}
我想这会给轴添加标签

private drawAxis() {
    this.g.append("g")
        .attr("class", "axis axis--x")
        .attr("transform", "translate(0," + this.height + ")")
        .call(d3.axisBottom(this.x))
        .classed('x axis', true)
        .call(this.x)
        .append('text')
        .attr("transform",
            "translate(" + (this.width/2) + " ," +
            (this.height + this.margin.top + 20) + ")")
        .style("text-anchor", "middle")
        .text("Letters");
    this.g.append("g")
        .attr("class", "axis axis--y")
        .call(d3.axisLeft(this.y).ticks(10, "%"))
        .append("text")
        .attr("class", "axis-title")
        .attr("transform", "rotate(-90)")
        .attr("y", 6)
        .attr("dy", "0.71em")
        .attr("text-anchor", "end")
        .text("Frequency");
}

x轴标签未显示,因为变换规则将其向下推得太远。它已经在转换为
translate(0,this.height)
的组中,因此只需再向下推25个像素左右


您可能需要为文本元素定义填充,方法是在代码中添加一行,称为
style('fill','black')
,或者在样式表中
.axis title{fill:black}
(不要忘了将
axis title
类添加到x轴标签中).

x轴标签未显示,因为变换规则将其向下推得太远。它已经在转换为
translate(0,this.height)
的组中,因此只需再向下推25个像素左右

您可能需要为文本元素定义填充,方法是在代码中添加一行,称为
style('fill','black')
,或者在样式表中
.axis title{fill:black}
(不要忘了将
axis title
类添加到x轴标签中)