score:1

Accepted answer

what i would do, is this :

  1. create a new date that has time 00:00:00 :

    date = new date('01-01-2016 00:00:00')

  2. turn that date into a timestamp :

    timestamp = date.gettime()

  3. add y seconds to that timestamp :

    timestamp = timestamp + (y * 1000)

  4. create a new date, using that value as input :

    date = new date(timestamp)

  5. use d3.time.format to format that date accordingly :

    time = d3.time.format("%h:%m:%s")(date)

  6. put all the pieces together and turn it into a oneliner :

    time = d3.time.format("%h:%m:%s")(new date(new date('01-01-2016 00:00:00').gettime() + (y * 1000)));

now, you can just put this oneliner into a format function for your y-axis and return time :

var chart = c3.generate({
    data : {
        x : 'x',
        columns : [
            ['x', '2010-01-01', '2011-01-01', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01'],
            ['sample', 30, 200, 100, 400, 150, 250]
        ]
    },
    axis : {
        x : {
            type: 'timeseries'
        },
        y : {
            tick : {
                format : function (y) {
                    return d3.time.format("%h:%m:%s")(new date(new date('01-01-2016 00:00:00').gettime() + (y * 1000)));
                }
            }
        }
    }
});

see this fiddle for a demo.


more info :

score:1

to also get this work with firefox you need to set:

fri jan 01 2016 00:00:00 gmt+0100 (cet)

instead of

01-01-2016 00:00:00

Related Query

More Query from same tag