Question: How do I find the maximum and minimum x-axis value of a RadCartesianChart's current viewport using DateTimeCategoricalAxis
?
I can easily find the maximum/minimum values of the dataset and, if I were to use a DateTimeContinousAxis
(unfortunately not an option), I could simply use ActualRange
and ActualVisibleRange
. However using DateTimeCategoricalAxis
is a completely different story, since I cannot accurately find the datapoints within the current viewport. I even tried using the PlotAreaClip
but to no avail. Not to mention, PlotAreaClip
does not take into account the zoom size, which becomes a problem.
Any help would be great appreciated!
Here is a simplified version of my code:
XAML:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<telerik:RadCartesianChart ZoomChanged="Zooming">
<telerik:RadCartesianChart.Behaviors>
<telerik:ChartPanAndZoomBehavior DragMode="Pan"
PanMode="Both"
ZoomMode="None" />
</telerik:RadCartesianChart.Behaviors>
<telerik:RadCartesianChart.Series>
<telerik:OhlcSeries ItemsSource="{Binding Bars}"
OpenBinding="Open"
HighBinding="High"
LowBinding="Low"
CloseBinding="Close"
CategoryBinding="Date">
</telerik:OhlcSeries>
</telerik:RadCartesianChart.Series>
<telerik:RadCartesianChart.HorizontalAxis>
<telerik:DateTimeCategoricalAxis DateTimeComponent="Ticks"
ShowLabels="False"
PlotMode="OnTicks"
MajorTickInterval="100">
</telerik:DateTimeCategoricalAxis>
</telerik:RadCartesianChart.HorizontalAxis>
<telerik:RadCartesianChart.VerticalAxis>
<telerik:LinearAxis HorizontalLocation="Right"
RangeExtendDirection="Both"
Minimum="{Binding PriceMinimum, Mode=OneWay}"
Maximum="{Binding PriceMaximum, Mode=OneWay}"
MajorStep="{Binding PriceMajorStep, Mode=OneWay}" />
</telerik:RadCartesianChart.VerticalAxis>
<telerik:RadCartesianChart.Grid>
<telerik:CartesianChartGrid MajorXLinesRenderMode="All"
MajorLinesVisibility="XY" />
</telerik:RadCartesianChart.Grid>
</telerik:RadCartesianChart>
</Grid>
</UserControl>
CODE BEHIND:
public void Zooming(object sender, ChartZoomChangedEventArgs e)
{
RadCartesianChart chart = sender as RadCartesianChart;
if (chart != null)
{
//PlotAreaClip.Location.X (PlotAreaClip.X also works) to get left side of clip
//PlotAreaClip.Right to get right side of clip
DataTuple dtMin = chart.ConvertPointToData(new Point(chart.PlotAreaClip.Location.X - Math.Abs(chart.PanOffset), chart.PlotAreaClip.Y), chart.HorizontalAxis, chart.VerticalAxis);
DataTuple dtMax = chart.ConvertPointToData(new Point(chart.PlotAreaClip.Right - Math.Abs(chart.PanOffset), chart.PlotAreaClip.Y), chart.HorizontalAxis, chart.VerticalAxis);
object xMin = dtMin.FirstValue;
object xMax = dtMax.FirstValue;
//these numbers are VERY inconsistent, especially when you zoom in!
}
}
The Telerik control being mentioned can be found here.
If anyone have any suggestions, I would greatly appreciate it! Thank you!