zoukankan      html  css  js  c++  java
  • Silverlight RadChart :创建十字定位&圈选

    //图像加载
            void Chart_Loaded(object sender, RoutedEventArgs e)
            {
                var plotAreaPanel = this.radChart.DefaultView.ChartArea.ChildrenOfType<ClipPanel>().FirstOrDefault();
                plotAreaPanel.MouseEnter += this.OnPlotAreaPanelMouseEnter;
                plotAreaPanel.MouseMove += this.OnPlotAreaPanelMouseMove;
                plotAreaPanel.MouseLeave += this.OnPlotAreaPanelMouseLeave;
            }               
    
            
            //进入--添加GridLine
            private void OnPlotAreaPanelMouseEnter(object sender, MouseEventArgs e)
            {
                if (null != xGridLine && null != yGridLine)
                {
                    xGridLine = new CustomGridLine();
                    yGridLine = new CustomGridLine();
    
                    this.radChart.DefaultView.ChartArea.Annotations.Add(xGridLine);
                    this.radChart.DefaultView.ChartArea.Annotations.Add(yGridLine);
                }
                else
                {
                    this.radChart.DefaultView.ChartArea.Annotations.Add(xGridLine);
                    this.radChart.DefaultView.ChartArea.Annotations.Add(yGridLine);
                }
            }
        
            //移动,实时跟踪
            private void OnPlotAreaPanelMouseMove(object sender, MouseEventArgs e)
            {
                var plotAreaPanel = sender as ClipPanel;
                var position = e.GetPosition(plotAreaPanel);
              
                var x = this.radChart.DefaultView.ChartArea.AxisX.ConvertPhysicalUnitsToData(position.X);
                var y = this.radChart.DefaultView.ChartArea.AxisY.ConvertPhysicalUnitsToData(position.Y);
    
                //十字线赋值
                xGridLine.XIntercept = x;
                yGridLine.YIntercept = y;
    
                this.textX.Text = string.Format("X: {0:N3}", x);
                this.textY.Text = string.Format("Y: {0:N3}", y);
            }
    
            //移出-->移除GridLine
            private void OnPlotAreaPanelMouseLeave(object sender, MouseEventArgs e)
            {
                this.radChart.DefaultView.ChartArea.Annotations.Remove(xGridLine);
                this.radChart.DefaultView.ChartArea.Annotations.Remove(yGridLine);
            }

     

    这个事件稍一改动,就可以有圈选的功效

    (这张图就不搞成动态gif了)

    换汤不换药,源码过一遍就明白了

    //进入
            private void OnPlotAreaPanelMouseEnter(object sender, MouseEventArgs e)
            {
                if (null != mz)
                {
                    mz = new MarkedZone();
                    mz.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xCC, 0x00));
                    this.radChart.DefaultView.ChartArea.Annotations.Add(mz);
                }
                else
                {
                    this.radChart.DefaultView.ChartArea.Annotations.Add(mz);
                }
            }
    
            //移动
            private void OnPlotAreaPanelMouseMove(object sender, MouseEventArgs e)
            {
                var plotAreaPanel = sender as ClipPanel;
                var position = e.GetPosition(plotAreaPanel);
    
                var x = this.radChart.DefaultView.ChartArea.AxisX.ConvertPhysicalUnitsToData(position.X);
                var y = this.radChart.DefaultView.ChartArea.AxisY.ConvertPhysicalUnitsToData(position.Y);
    
                mz.StartX = 0;  //可自定义,设置初始值,本次案例不做安排
                mz.EndX = x;   
                mz.StartY = 0;  
                mz.EndY = y;   
    
                this.textX.Text = string.Format("X: {0:N3}", x);
                this.textY.Text = string.Format("Y: {0:N3}", y);
            }
    
            //移出
            private void OnPlotAreaPanelMouseLeave(object sender, MouseEventArgs e)
            {
                this.radChart.DefaultView.ChartArea.Annotations.Remove(mz);
            }

     原文链接:http://www.telerik.com/help/silverlight/radchart-howto-create-location-crosshair-for-radchart.html

  • 相关阅读:
    ATS(App Transport Security)对HTTP协议屏蔽引起的问题
    后台子线程(非主线程)更新UI引起的警告
    Xcode无法启动ios模拟器的问题
    UIButton修改文字大小问题
    imageNamed和imageWithContentsOfFile-无法加载图片的问题
    storyboard在ios模拟器无法显示的问题
    返回一个数组的连续子数组和的最大值
    第二周学习进度总结
    软件工程开学第一节课课堂测试
    第一周学习进度总结
  • 原文地址:https://www.cnblogs.com/Feng-Scorpio/p/3492341.html
Copyright © 2011-2022 走看看