issue of xAxis "timeseries" not work with format '%Y-%m' and '%Y' (format of data is json)
- Dominant language
- JavaScript
- Stars
- 9.3k
- Forks
- 1.4k
- Avg merge
- 6d 16h
- Merged PRs (30d)
- 1
Description
Bonjour masayuki,
I use c3.js to create three stacked bar charts. C3.js works well with the xAxis "timeseries" in the formats '%Y-%m-%d' , but nor work with the format '%Y-%m' and '%Y'.
I debug the code of C3.js , and I found a solution:
In file c3.js, add the code :
``` sh
data_xFormat2: '%Y-%m',
```
then I modifies un function
``` sh
c3_chart_internal_fn.parseDate = function (date) {
var $$ = this, parsedDate;
if (date instanceof Date) {
parsedDate = date;
} else if (typeof date === 'string') {
parsedDate = $$.dataTimeFormat($$.config.data_xFormat).parse(date);
} else if (typeof date === 'number' || !isNaN(date)) {
parsedDate = new Date(+date);
}
if (!parsedDate || isNaN(+parsedDate)) {
window.console.error("Failed to parse x '" + date + "' to Date object");
}
return parsedDate;
};
```
to
``` sh
c3_chart_internal_fn.parseDate = function (date) {
var $$ = this, parsedDate;
if (date instanceof Date) {
parsedDate = date;
} else if (typeof date === 'string') {
parsedDate = $$.dataTimeFormat($$.config.data_xFormat).parse(date);
//emma add this code to solve problem in stacked barchart
if (!parsedDate || isNaN(+parsedDate)){
parsedDate = $$.dataTimeFormat($$.config.data_xFormat2).parse(date);}
//code end
} else if (typeof date === 'number' || !isNaN(date)) {
parsedDate = new Date(+date);
}
if (!parsedDate || isNaN(+parsedDate)) {
window.console.error("Failed to parse x '" + date + "' to Date object");
}
return parsedDate;
};
```
Contributor guide
Assessment
This issue has not been assessed yet.