This is a migrated thread and some comments may be shown as answers.

categoryAxis Line Chart

3 Answers 55 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Paul McNamara
Top achievements
Rank 1
Paul McNamara asked on 29 Apr 2015, 01:09 PM

Hi

kendo v2014.2.1008

I am trying to implement one of your chart components and I am unable to get some of the date formats to work as required.

Using the MVC helper, I have tried doing the following:
CategoryAxis(axis => axis
            .Date()
            .MaxDateGroups(12)                 
            .BaseUnit(ChartAxisBaseUnit.Weeks)
                    .WeekStartDay(Model.WeekBeginningDay)
                    .Labels(labels => labels
                                .DateFormats(formats => formats
                                    .Seconds("HH:mm:ss")
                                    .Minutes("HH:mm")
                                    .Hours("HH:mm")
                                    .Days("dd/MM")
                                    .Weeks("dd/MM")
                                    .Months("MMM yy")
                                    .Years("yyyy"))
                              )

If I change the base unit to Months or Years then the formats used above do work (as proven by making changes to them). The Weeks format never seems to be applied.

Using the above, if I inspect the chart object in the developer tools console, I can see that only only some of those specified appear in the chart.options.categoryAxis.labels.dateFormats property (Weeks is not present).

If I set .Autobind(false) and then set these on document.ready() as follows:
        var DateLabelFormats = {
            seconds: "HH:mm:ss",
            minutes: "HH:mm",
            hours: "HH:mm",
            days: "d/M",
            weeks: "d/M",
            months: "MMM 'yy",
            years: "yyyy"
        };
        var chart = $("#ProjectHoursLineChart").data("kendoChart")
        chart.options.categoryAxis.dateFormats = DateLabelFormats;
        chart.dataSource.read();

When I inspect the chart object in the developer tools console I can see all formats are present, but still the Weeks format is not applied.

Can anyone please tell me how I get the date formats to work as specified above (I would like to use ChartAxisBaseUnit.Fit)?

Many thanks in advance

 

3 Answers, 1 is accepted

Sort by
0
Paul McNamara
Top achievements
Rank 1
answered on 29 Apr 2015, 01:38 PM

I should add to the original post that I am loading the culture specific kendo.culture.en-GB.min.js and setting the current kendo.culture("en-GB") and expected the controls to format to those culture defaults.

Nevertheless, this is not so and I have had to attempt to enforce the formatting.
I also tried using chart.refresh() before datasource.read() to see if that made any difference but this did not work either.

0
Paul McNamara
Top achievements
Rank 1
answered on 30 Apr 2015, 03:28 PM

It seems there is a bug in the MVC helper which Telerik are going to investigate. 

The workaround is to do the following in document.ready()

You may want to set .Autobind(false)

var DateLabelFormats = {
                seconds: "HH:mm:ss",
                minutes: "HH:mm",
                hours: "HH:mm",
                days: "d/M",
                weeks: "d/M",
                months: "MMM 'yy",
                years: "yyyy"
            };
var chart = $("#LineChart").data("kendoChart")

chart.options.categoryAxis.labels.dateFormats = DateLabelFormats;
chart.refresh();
chart.dataSource.read();

 

Note that I had originally missed the labels property...

0
T. Tsonev
Telerik team
answered on 01 May 2015, 04:33 PM
Hi,

Thank you for sharing this solution with the community.
The issue should be fixed in the latest internal build (2015.1.430) as well.

Apologies for the caused inconvenience.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Charts
Asked by
Paul McNamara
Top achievements
Rank 1
Answers by
Paul McNamara
Top achievements
Rank 1
T. Tsonev
Telerik team
Share this question
or