I'm trying to dynamically adjust the tick marks and labels on a RadCartesianChart using MajorTickInterval and LabelInterval when zooming to maintain an acceptable look. However, the chart does not maintain the specified MajorTickInterval when zooming, and I haven't been able to figure out the specifics of the behavior to adjust accordingly.
Here's a simple example to illustrate.
XAML:
Code-behind:
Run the example and notice that initially it correctly renders major ticks every 5 data points, and labels every 2 major ticks, just as specified in the code. This displays 50 labels. Now move the max zoom slider on the horizontal axis back to about the 2/3 mark and the axis shifts from using 5 points between major ticks to 2. The labels continue to show every 2 major ticks, so now it is displaying 81 labels, which is much more crowded than desired (even more-so in my real application).
Even more problematically, the value of MajorTickInterval remains 5 even though the display has changed, so I have no way to re-calculate the LabelInterval appropriately to maintain the number of labels I want.
Is this a bug, or is there an algorithm at work here? If the latter, how can I determine what the interval actually is to adjust the labels correctly?
I'm using the 2013 1204 build.
Thanks,
Louis
Here's a simple example to illustrate.
XAML:
<
Window
x:Class
=
"ZoomMajorTickInterval.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"1280"
>
<
Grid
>
<
telerik:RadCartesianChart
x:Name
=
"Chart"
>
<
telerik:RadCartesianChart.Grid
>
<
telerik:CartesianChartGrid
MajorLinesVisibility
=
"XY"
/>
</
telerik:RadCartesianChart.Grid
>
<
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:CategoricalAxis
LabelFitMode
=
"Rotate"
/>
</
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:LinearAxis
/>
</
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:RadCartesianChart.Behaviors
>
<
telerik:ChartPanAndZoomBehavior
ZoomMode
=
"Both"
PanMode
=
"Both"
/>
</
telerik:RadCartesianChart.Behaviors
>
<
telerik:RadCartesianChart.Series
>
<
telerik:LineSeries
ItemsSource
=
"{Binding MyData}"
CategoryBinding
=
"PeriodText"
ValueBinding
=
"DataValue"
/>
</
telerik:RadCartesianChart.Series
>
</
telerik:RadCartesianChart
>
</
Grid
>
</
Window
>
Code-behind:
using
System;
using
System.Windows;
using
System.Collections.ObjectModel;
using
Telerik.Windows.Controls.ChartView;
namespace
ZoomMajorTickInterval
{
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
Random r =
new
Random();
MyData =
new
ObservableCollection<DataPoint>();
for
(
int
ctr = 0; ctr < 500; ctr++)
MyData.Add(
new
DataPoint() { PeriodText =
"Q"
+ ctr.ToString(), DataValue = r.Next(1000) });
DataContext =
this
;
CategoricalAxis axis = Chart.HorizontalAxis
as
CategoricalAxis;
axis.MajorTickInterval = 5;
Chart.HorizontalAxis.LabelInterval = 2;
}
public
ObservableCollection<DataPoint> MyData {
get
;
set
; }
}
public
class
DataPoint
{
public
string
PeriodText {
get
;
set
;}
public
int
DataValue {
get
;
set
; }
}
}
Run the example and notice that initially it correctly renders major ticks every 5 data points, and labels every 2 major ticks, just as specified in the code. This displays 50 labels. Now move the max zoom slider on the horizontal axis back to about the 2/3 mark and the axis shifts from using 5 points between major ticks to 2. The labels continue to show every 2 major ticks, so now it is displaying 81 labels, which is much more crowded than desired (even more-so in my real application).
Even more problematically, the value of MajorTickInterval remains 5 even though the display has changed, so I have no way to re-calculate the LabelInterval appropriately to maintain the number of labels I want.
Is this a bug, or is there an algorithm at work here? If the latter, how can I determine what the interval actually is to adjust the labels correctly?
I'm using the 2013 1204 build.
Thanks,
Louis