c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.34k stars 1.39k forks source link

Tick format YYYYMMDD problem with two months range #579

Closed Tropicalista closed 10 years ago

Tropicalista commented 10 years ago

I'm trying to use c3js to display some analytics data chart. I have an array of date where date are in format YYYYMMDD. I try to convert this string to date using axis.x.tick.format without success.

The problem happen only if the range of date is between two months, but with all range in same month it works.

I'm using this format function:

    tick: {
        format: function (x) {
            str = x.toString();
            y = str.substr(0,4)
            m = str.substr(4,2)
            d = str.substr(6,2)
           var D = new Date(y,m,d);
           return D;
        }
    }

Please check this fiddle to view the problem: check this fiddle

Tropicalista commented 10 years ago

Just to be more exhaustive look at this image: screenshot

SamMorrowDrums commented 10 years ago

The format function only changes the text, C3 was looking at the your date strings as numbers, I converted them before putting them in the graph.

Here is the fixed fiddle

Also have a look at D3s date formatter. You should consider using data.xFormat from the C3 library itself, if you have to pass date strings around, rather than date objects. I think that way you can get C3 to automatically decode the dates for you.

Tropicalista commented 10 years ago

Yes, I ended with similar solution. Thanks

SamMorrowDrums commented 10 years ago

Cool, you can close this issue then, if it is resolved. I am not an admin, and I didn't create it so I cannot. Thanks!