d3.js轴标签 - 颜色不变 [英] d3.js axis labels - color not changing

查看:497
本文介绍了d3.js轴标签 - 颜色不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下文本创建轴,但是标签的颜色未正确更改;颜色文本保持黑色。有人知道为什么?

I'm creating my axis with the following text, however the color of the labels is not changing properly; the color the text remains black. Does anybody know why?

  // create Axis
  svg.selectAll(".axis")
      .data(d3.range(angle.domain()[1]))
    .enter().append("g")
      .attr("class", "axis")
      .attr("transform", function(d) { return "rotate(" + angle(d) * 180 / Math.PI + ")"; })
    .call(d3.svg.axis()
      .scale(radius.copy().range([-5, -outerRadius]))
      .ticks(5)
      .orient("left"))
    .append("text")
      .attr("y", 
        function (d) {
          if (window.innerWidth < 455){
            return -(window.innerHeight * .33);
          }
          else{
            return -(window.innerHeight * .33);
          }
        })
      .attr("dy", ".71em")
      .attr("text-anchor", "middle")
      .text(function(d, i) { return capitalMeta[i]; })
      .attr("style","font-size:12px;")
      .style("color","#DE3378");   <--------------- adding color attribute here...

EDIT
- 尝试使用以下代码为不同轴标签颜色设置不同的颜色,但这不正常...

EDIT - trying to color different axis labels different colors with the following code, however this is not working properly...

  .style(function() {
      for (var i = 0; i < unhealthyArray.length; i++) {
              if ($.inArray(unhealthyArray[i], capitalMeta) != -1)
                    return "fill","red";
              else
                    return "fill","black";
      }
  });


推荐答案

您需要使用 stroke 属性(对于大纲)或 fill (对于填充颜色)。参见例如本教程

You need to use the stroke attribute (for the outline) or fill (for the fill colour). See e.g. this tutorial.

这篇关于d3.js轴标签 - 颜色不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆