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

Datetime Category Axis - Min and Max BaseUnit

2 Answers 276 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 03 Sep 2018, 12:08 PM

I have a zoomable chart with a datetime category axis.The ChartAxisBaseUnit is set to Fit.

I can zoom until I reached the milliseconds unit.

Can I limit the Max and Min Base Unit, so I can only zoom between Unit Year and Day?

 

01.@(Html.Kendo().Chart(Model.Stats.Items)
02.        .Name("temperaturechart")
03.        .Title(title => title
04.            .Text("Temperature")
05.            .Visible(true)
06.            .Position(ChartTitlePosition.Top))
07.        .Legend(legend => legend
08.            .Visible(true)
09.            .Position(ChartLegendPosition.Bottom)
10.        )
11.        .ChartArea(chart => chart
12.            .Background("transparent")
13.        )
14.        .Series(series =>
15.        {
16.            series
17.                .Line(model => model.Temperature, categoryExpression: model => model.Date)
18.                .Aggregate(ChartSeriesAggregate.Avg)
19.                .Name("Temperature");
20.        })
21.        .ValueAxis(axis => axis.Labels(label => label.Format("{0:0} °C")))
22.        .CategoryAxis(axis => axis
23.            .Date()
24.            .Labels(x => x.Rotation(310))
25.            .BaseUnit(ChartAxisBaseUnit.Fit)
26.        )
27.        .Tooltip(tooltip => tooltip
28.            .Visible(true)
29.            .Format("{0:0.0} °C")
30.        )
31.        .Pannable(pannable => pannable
32.            .Lock(ChartAxisLock.Y)
33.        )
34.        .Zoomable(zoomable => zoomable
35.            .Mousewheel(mousewheel => mousewheel.Lock(ChartAxisLock.Y))
36.            .Selection(selection => selection.Lock(ChartAxisLock.Y))
37.        )
38.)

 

Thanks,

Alex

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetina
Telerik team
answered on 04 Sep 2018, 11:45 AM
Hello Alexander,

To prevent the Chart from entering minutes, seconds and millisecond categories, you can set 0 values for the AutoBaseUnitsSteps collections for Hours, Minutes, Seconds and Milliseconds:
.CategoryAxis(axis => axis
    .Date()
    .BaseUnit(ChartAxisBaseUnit.Fit)
    .AutoBaseUnitSteps(steps =>
    {
        steps.Milliseconds(new int[] { 0 });
        steps.Seconds(new int[] { 0 });
        steps.Minutes(new int[] { 0 });
        steps.Hours(new int[] { 0 });
    })
    .Labels(labels => labels.Rotation(-90))
    .MajorGridLines(lines => lines.Visible(false))
)

The autoBaseUnitSteps property is explained in more detail in the client API documentation: categoryAxis.autoBaseUnitSteps.


Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alexander
Top achievements
Rank 1
answered on 04 Sep 2018, 12:36 PM

Thanks Tsvetina, it´s working.

Best regards,

Alexander

Tags
Chart
Asked by
Alexander
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or