01
2015
09

如何更改Telerik控件ChartView的坐标轴浮动标注的位置

            <telerik:RadCartesianChart.Behaviors>
                <telerik:ChartCrosshairBehavior PositionChanged="ChartCrosshairBehavior_PositionChanged" />
            </telerik:RadCartesianChart.Behaviors>


    在后台更改位置即可

        private void ChartCrosshairBehavior_PositionChanged(object sender, ChartCrosshairPositionChangedEventArgs e)
        {
            {
                var crosshair = (ChartCrosshairBehavior)this.chart1.Behaviors[0];
                if (e.Position.X < 100 && crosshair.HorizontalLineLabelDefinition.HorizontalAlignment == HorizontalAlignment.Right)
                {
                    if (e.Position.Y > 60)
                    {
                        crosshair.VerticalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            VerticalAlignment = crosshair.VerticalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.VerticalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 0,
                        };
                        crosshair.HorizontalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            VerticalAlignment = crosshair.HorizontalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.HorizontalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 2,
                        };
                    }
                    else
                    {
                        crosshair.VerticalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            VerticalAlignment = crosshair.VerticalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.VerticalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 2,
                        };
                        crosshair.HorizontalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            VerticalAlignment = crosshair.HorizontalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.HorizontalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 0,
                        };
                    }
                }

                if (e.Position.X > 100 && crosshair.HorizontalLineLabelDefinition.HorizontalAlignment == HorizontalAlignment.Left)
                {
                    if (e.Position.Y > 60)
                    {
                        crosshair.VerticalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Right,
                            VerticalAlignment = crosshair.VerticalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.VerticalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 0,
                        };
                        crosshair.HorizontalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Right,
                            VerticalAlignment = crosshair.HorizontalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.HorizontalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 2,
                        };
                    }
                    else
                    {
                        crosshair.VerticalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Right,
                            VerticalAlignment = crosshair.VerticalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.VerticalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 2,
                        };
                        crosshair.HorizontalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                        {
                            Location = ChartAnnotationLabelLocation.Inside,
                            HorizontalAlignment = HorizontalAlignment.Right,
                            VerticalAlignment = crosshair.HorizontalLineLabelDefinition.VerticalAlignment,
                            DefaultVisualStyle = crosshair.HorizontalLineLabelDefinition.DefaultVisualStyle,
                            HorizontalOffset = 2,
                            VerticalOffset = 0,
                        };
                    }
                }

                if (e.Position.Y < 60 && crosshair.HorizontalLineLabelDefinition.VerticalAlignment == VerticalAlignment.Bottom)
                {
                    crosshair.VerticalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                    {
                        Location = ChartAnnotationLabelLocation.Inside,
                        HorizontalAlignment = crosshair.VerticalLineLabelDefinition.HorizontalAlignment,
                        VerticalAlignment = VerticalAlignment.Top,
                        DefaultVisualStyle = crosshair.VerticalLineLabelDefinition.DefaultVisualStyle,
                        HorizontalOffset = 2,
                        VerticalOffset = 2,
                    };
                    crosshair.HorizontalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                    {
                        Location = ChartAnnotationLabelLocation.Inside,
                        HorizontalAlignment = crosshair.HorizontalLineLabelDefinition.HorizontalAlignment,
                        VerticalAlignment = VerticalAlignment.Top,
                        DefaultVisualStyle = crosshair.HorizontalLineLabelDefinition.DefaultVisualStyle,
                        HorizontalOffset = 2,
                        VerticalOffset = 0,
                    };
                }

                if (e.Position.Y > 60 && crosshair.HorizontalLineLabelDefinition.VerticalAlignment == VerticalAlignment.Top)
                {
                    crosshair.VerticalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                    {
                        Location = ChartAnnotationLabelLocation.Inside,
                        HorizontalAlignment = crosshair.VerticalLineLabelDefinition.HorizontalAlignment,
                        VerticalAlignment = VerticalAlignment.Bottom,
                        DefaultVisualStyle = crosshair.VerticalLineLabelDefinition.DefaultVisualStyle,
                        HorizontalOffset = 2,
                        VerticalOffset = 0,
                    };
                    crosshair.HorizontalLineLabelDefinition = new ChartAnnotationLabelDefinition()
                    {
                        Location = ChartAnnotationLabelLocation.Inside,
                        HorizontalAlignment = crosshair.HorizontalLineLabelDefinition.HorizontalAlignment,
                        VerticalAlignment = VerticalAlignment.Bottom,
                        DefaultVisualStyle = crosshair.HorizontalLineLabelDefinition.DefaultVisualStyle,
                        HorizontalOffset = 2,
                        VerticalOffset = 2,
                    };
                }

            }
        }

 

« 上一篇下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。