首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >查找当前视图端口的最大值/最小值

查找当前视图端口的最大值/最小值
EN

Stack Overflow用户
提问于 2013-09-10 18:36:06
回答 1查看 1.7K关注 0票数 1

问题:如何使用DateTimeCategoricalAxis找到RadCartesian图表当前视图的最大和最小x轴值

我可以很容易地找到数据集的最大值/最小值,如果我要使用一个DateTimeContinousAxis(不幸的不是一个选项),我可以简单地使用ActualRangeActualVisibleRange。然而,使用DateTimeCategoricalAxis是一个完全不同的故事,因为我无法准确地找到当前视图端口中的数据点。我甚至尝试使用PlotAreaClip,但都没有效果。更不用说,PlotAreaClip没有考虑缩放大小,这就成了一个问题。

任何帮助都将不胜感激!

下面是我的代码的简化版本:

XAML:

代码语言:javascript
代码运行次数:0
运行
复制
<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>

背后的代码:

代码语言:javascript
代码运行次数:0
运行
复制
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!
        }
    }

提到的远程控制可以找到这里

如果有人有任何建议,我会非常感激的!谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-16 19:05:07

在进行了一些调查之后,我找到了这个线程的解决方案:

代码语言:javascript
代码运行次数:0
运行
复制
private DataPoint[] FindFirstLastVisiblePoints(CategoricalSeries series)
{
    DataPoint firstPoint = null;
    DataPoint lastPoint = null;
    RadRect plotArea = this.radChart1.PlotAreaClip;

    foreach (DataPoint point in series.DataPoints)
    {
        if (point.LayoutSlot.IntersectsWith(plotArea))
        {
            if (firstPoint == null)
            {
                firstPoint = point;
            }
            lastPoint = point;
        }
    }

    return new DataPoint[] { firstPoint, lastPoint };
}

基本上,该方法接受当前的PlotAreaClip并返回当前ViewPort中的第一个也是最后一个数据点。我真的希望这对将来的其他人有帮助!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18726453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档