How to get proper DateTime format for ValueAxis

1 Answer 57 Views
Chart
Simon
Top achievements
Rank 1
Simon asked on 20 Jun 2023, 08:22 PM | edited on 21 Jun 2023, 06:49 PM

The Value Axis isn't showing a DateTime like '5/1/2023 10:00 AM' which is the same DateTime format that the data from my stored procedure is using. I'd like the value axis to show each hour of the day.

Attached is a screenshot of the grid. Thanks!

Here's the chart's code:

 @(Html.Kendo().Chart<BatchPlantHourlyOutputViewModel>()
    .Name("chart")
    .Title("Planned Pour Delivery Times vs Actual Pour Delivery Times")
    .Legend(legend => legend
        .Visible(true)
        .Position(ChartLegendPosition.Bottom)
    )

    .DataSource(dataSource => dataSource
        .Read(read => read.Action("GetBatchPlantHourlyOutputGraph", "Production")
        .Data("PSW.UI.getSelectedInputVals(false)")))
        .Events(e => e.DataBound("PSW.Events.Graph.onBatchPlantHourlyOutputGraphDataBound"))

    .Series(series =>
    {
        series.Line(model => model.ScheduledHour)
           .Name("Scheduled Time");

        series.Line(model => model.StartTime)
            .Name("Actual Time");
    })

    .CategoryAxis(axis => axis
        .Categories(model => model.Output)
        .MajorGridLines(lines => lines.Visible(true))
    )

    .ValueAxis(axis => axis
        .Date()      
        .Labels(labels => labels.Format("{0:MM/dd/yyyy hh:mm:ss}"))
        .Line(line => line.Visible(false))
    )
    )

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 22 Jun 2023, 01:17 PM

Hello Simon,

Thank you for the code snippet, image, and details provided.

In order to achieve the desired behavior, I would recommend using the approach from the following article:

Here is a dojo example:

Give a try to the approach above and let me know if it achieves the desired result.

Kind Regards,
Anton Mironov
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.

Simon
Top achievements
Rank 1
commented on 22 Jun 2023, 02:18 PM

That fixed it! Thank you very much!
Tags
Chart
Asked by
Simon
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
Share this question
or