C3: Only integers on Y axis

Created on 30 Apr 2015  路  6Comments  路  Source: c3js/c3

Hi, the Y range is just 0-5: so the graph renders automatically 2 things I don't need:

  • fractionals values: 1.5, 2.5
  • a negative -0.5 value

How can avoid those both?

Most helpful comment

yes, it works but it still shows the ticks for those floating values. So I think this option only hides label for the floating values:

screenshot from 2017-08-01 12 04 32

How can I stop generating it? i.e not just hiding labels.

Here is the complete code which I'm using:

c3.generate({
    bindto: '#user-reg-linechart',
    data: {
        x: 'x',
        columns: [
            registrationDates,
            registrationCount
        ]
    },
    axis: {
        x: {
            type: 'timeseries',
            tick: {
                format: '%Y-%m-%d'
            }
        },
        y: {
            min: 0,
            tick: {
                format: d3.format('d')
            },
            padding: {top: 0, bottom: 0}
        }
    }
});

All 6 comments

I solved my problem of fractionals values with

tick: {
    format: function(d) {
        return d3.round(d); //this wil round the number (1.5 will be rounded to 1)
    }
}

But you should try to use the format function d3.format("d")
More info here in the d3 formatting documentation

Greetings

it works indeed with
tick: { format: d3.format("d") }

thanks

yes, it works but it still shows the ticks for those floating values. So I think this option only hides label for the floating values:

screenshot from 2017-08-01 12 04 32

How can I stop generating it? i.e not just hiding labels.

Here is the complete code which I'm using:

c3.generate({
    bindto: '#user-reg-linechart',
    data: {
        x: 'x',
        columns: [
            registrationDates,
            registrationCount
        ]
    },
    axis: {
        x: {
            type: 'timeseries',
            tick: {
                format: '%Y-%m-%d'
            }
        },
        y: {
            min: 0,
            tick: {
                format: d3.format('d')
            },
            padding: {top: 0, bottom: 0}
        }
    }
});

@ParthVora777 Did you find your solution?

I'm facing the same issue as @ParthVora777 pointed out. Does anyone have a solution?

        tick: {
          // format: d3.format('d')
          format: function(d) {
            if (Math.floor(d) != d){
              return;
            }
            return d;
          }
        },

This turns my chart Y axis looks like:

image

Ref: https://stackoverflow.com/questions/12643591/how-to-limit-d3-svg-axis-to-integer-labels

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alantygel picture alantygel  路  3Comments

udhaya2kmrv picture udhaya2kmrv  路  3Comments

jstone-ponderosa picture jstone-ponderosa  路  3Comments

DieterSpringer picture DieterSpringer  路  4Comments

kethomassen picture kethomassen  路  3Comments