C3js: How to hide ticks on y-axis? Y-Axis label is cut off
Asked Answered
F

3

7

How can I hide the ticks on the y-axis?

I currently achieve it by editing tick.format, as can be seen in this JSFiddle http://jsfiddle.net/DanielApt/bq17Lp02/1/

I'm not happy with this solution, as the y-axis label is being cut off

Screenshot showing the y-axis label is being cut off

So how can I hide ticks without having y-axis label being cut off?

Thank you for your help in advance!

Fari answered 4/12, 2014 at 12:29 Comment(0)
F
1

In the end I used a combination of Chetan's answer and some further work:

I hid the ticks with:

.c3-axis-y .tick {
   display: none;
}

And I set the tick format:

axis.y.tick.format = function(){return 'fy'; }
//return characters with both ascenders and descenders

See this JS Fiddle http://jsfiddle.net/DanielApt/etuwo8mz/1/ for the solution in action.

Fari answered 8/12, 2014 at 14:9 Comment(1)
You can also do it in the method: ` onrendered: function() { d3.selectAll(".c3-axis.c3-axis-y .tick") .style("fill", "none"); } `Pyroligneous
G
10

1) Try setting axis.y.tick.count to 1, so that no ticks are shown except top, and bottom most.

2) Or try CSS to get ride of all intermediate ticks except top and bottom one like:-

.c3-axis-y .tick {
   display: none;
}

If axis label positioning is an issue try to position it somewhere else like:-

axis: {
    x: {
        label: {
            text: 'X Label',
            position: 'outer-center'
            // inner-right : default
            // inner-center
            // inner-left
            // outer-right
            // outer-center
            // outer-left
        }
    },

Here is the working code:- http://jsfiddle.net/chetanbh/24jkmvL5/

Reference Url : http://c3js.org/samples/axes_label_position.html

Grimace answered 4/12, 2014 at 16:48 Comment(0)
A
3

In case someone still needs it, I put it in onrendered callback to avoid affecting all charts:

onrendered: function() {
      d3.select("#myChartContainer").selectAll(".c3-axis-x .tick line").style("display", "none");
}
Anisotropic answered 1/3, 2018 at 15:18 Comment(0)
F
1

In the end I used a combination of Chetan's answer and some further work:

I hid the ticks with:

.c3-axis-y .tick {
   display: none;
}

And I set the tick format:

axis.y.tick.format = function(){return 'fy'; }
//return characters with both ascenders and descenders

See this JS Fiddle http://jsfiddle.net/DanielApt/etuwo8mz/1/ for the solution in action.

Fari answered 8/12, 2014 at 14:9 Comment(1)
You can also do it in the method: ` onrendered: function() { d3.selectAll(".c3-axis.c3-axis-y .tick") .style("fill", "none"); } `Pyroligneous

© 2022 - 2024 — McMap. All rights reserved.