Skip to content
Advertisement

Need to Hide or Remove alternative x-axis values in d3 charts

In x-axis I need to show only values like – 0.5, 1.5, 2.5, 3.5 and hide/remove other value labels(0.0, 1.0, 2.0 etc.,). I’m using D3 v3.

Chart Output should be like in the below image

Chart Output should be like in the below image

This is the code:

JavaScript
JavaScript

Advertisement

Answer

Use tickValues and a remainder operator to check for integers:

JavaScript

Here is the code with that change:

JavaScript
JavaScript
JavaScript
Advertisement