C3 charts don't want decimal numbers in y axis
Asked Answered
K

2

5

As you can see in output I am getting decimal values in y axis. These are number of downloads it cant be 1.5.

I tried giving min value but unable to get the result.

Also on mouse over in grid I am always getting value zero 0(Above microsoft in image). Can I have my custom text there?

function draw_tech_chart(){ 
        var chart = c3.generate({
            bindto: "#tech_chart",
            data: {
                columns: [['Microsoft', 5],['WebApplicationDevelopment', 2],['OpenSource', 2],['Content Management ', 2],['Open Source Middleware', 1],],
                type : 'bar',
                onclick: function (d, i) { console.log("onclick", d, i); },
                onmouseover: function (d, i) { console.log("onmouseover", d, i); },
                onmouseout: function (d, i) { console.log("onmouseout", d, i); }
            },size: {
              height: 250
            }               
        });

enter image description here

Khabarovsk answered 29/7, 2015 at 14:32 Comment(0)
F
18

Just format the y ticks to not display the labels

var chart = c3.generate({
    bindto: "#tech_chart",
    ...
    axis: {
        y: {
            tick: {
                format: function (d) {
                    return (parseInt(d) == d) ? d : null;
                }
            }
        }
    }
});

Alternatively, you could also loop through the values, find the max and set the y tick values manually to integers or integer multiples from 0 to max+ (see http://c3js.org/reference.html#axis-y-tick-value)


Fiddle - http://jsfiddle.net/ovvywb5j/

Feudalism answered 29/7, 2015 at 15:22 Comment(0)
T
1

You just need to manually compute the values on Y axis. You could also format the title of tooltip:

axis: {
    y: {
        tick : {values: [0,1,2,3,4,5]}
    }
}, tooltip: {
    format: {
        title: function (d) { return 'Custom text'; },
    }
}

Fiddle: http://jsfiddle.net/yymcjhgv/

Thirdrate answered 29/7, 2015 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.