DEV Community

Cover image for D3js, CSS styles
Ștefan Vîlce
Ștefan Vîlce

Posted on

D3js, CSS styles

I have to work with a creating of some charts for some statistics.
Image description

The data are comming from a JSON REST API. For one of the requests I have to count the occurencies of new articles for every single day. I have met many problems being for the first time when I work with D3js library (https://d3js.org/) which seems to be the best way to build charts in Javascript. And it is a very nice solution for that. But, I've been hit by some issues. For instance, I could't change the color of my texts on the chart. I've been trying to change the style for color but it didn't work.

Image description

The problem was solved whe I found out that I souldn't use:
.style("color", "#87A3C3")

The right solution for this problem is:
.attr("fill", "#87A3C3")

So, use attr instead of style!

Top comments (0)