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!

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs