欢迎光临
王新路的个人主页空间
我的地盘我做主

.net路上的探索

博客园 首页 新随笔 联系 订阅 管理

前不久因为项目需要学习了NI MeasurementStudio里关于做图的控件!网上看了下,这方面的文章还真是少,所以现在我抛砖引玉写点我的应用心得!
现在开始:
首先呢肯定是要下载安装,我就懒的说了!
引用好了后,我就说一下
1.怎样给graph打格子,看看下图可能您就明白了.

2.画图代码如下:
PlotY(object yData);
ChartY(object yData);
PlotXvsY(object xData, object yData);
ChartXvsY(object xData, object yData);
3.一些代码:

#region 加载标识
        /// <summary>
        /// 添加通道
        /// </summary>
        /// <param name="color">颜色被定义为uint,并且以颜色的BGR(标准为RGB)的值排列 如:000000255为红色</param>
        /// <param name="xPostion1">通道线的x坐标</param>
        /// <param name="xPostion2">通道线的x坐标</param>
        private void AddChannelMaker(uint color, object xPostion1, object xPostion2, bool visible)
        {
            Graph.TrackMode = CWUIControlsLib.CWGraphTrackModes.cwGTrackPlotAreaEvents;
            CWUIControlsLib.CWCursor Cursors1 = Graph.Cursors.Add();
            CWUIControlsLib.CWCursor Cursors2 = Graph.Cursors.Add();
            Cursors1.Name = "Cursors1";
            Cursors2.Name = "Cursors2";
            Cursors1.Color = color;
            Cursors2.Color = color;
            Cursors1.CrosshairStyle = CWUIControlsLib.CWCrosshairStyles.cwCrosshairMajorX;
            Cursors2.CrosshairStyle = CWUIControlsLib.CWCrosshairStyles.cwCrosshairMajorX;
            Cursors1.XPosition = xPostion1;
            Cursors2.XPosition = xPostion2;
            Cursors1.Visible = visible;
            Cursors2.Visible = visible;
            Cursors1.SnapMode = CWUIControlsLib.CWCursorSnapModes.cwCSnapAnchoredToPoint;
            Cursors2.SnapMode = CWUIControlsLib.CWCursorSnapModes.cwCSnapAnchoredToPoint;
        }
        /// <summary>
        /// 关闭通道显示
        /// </summary>
        private void RemoveChanel()
        {
            try
            {
                Graph.Cursors.Remove("Cursors2");
                Graph.Cursors.Remove("Cursors1");
            }
            catch { }
        }
        /// <summary>
        /// 清除所有Maker和通道显示
        /// </summary>
        private void RemoveAllMaker()
        {
            Graph.Cursors.RemoveAll();
            marker1onoff = false;
            #region markeroff
            try
            {
                RemoveMaker("m1");
            }
            catch
            { }
            try
            {
                RemoveMaker("m2");
            }
            catch
            { }
            try
            {
                RemoveAnnotation("Marker1");
            }
            catch
            { }
            try
            {
                RemoveAnnotation("Marker2");
            }
            catch
            { }
            #endregion
            DeltaShowItem.Enabled = false;
            DeltaStripButton.Enabled = false;
        }
        /// <summary>
        /// 添加箭头
        /// </summary>
        /// <param name="x">箭尾x坐标</param>
        /// <param name="y">箭尾y坐标</param>
        /// <param name="xPostion">箭头x坐标</param>
        /// <param name="yPostion">箭头y坐标</param>
        private void AddArrow(double x, double y, object xPostion, object yPostion)
        {
            CWUIControlsLib.CWAnnotation annotation = Graph.Annotations.Add();
            annotation.Caption.XCoordinate = x;
            annotation.Caption.YCoordinate = y;
            annotation.Shape.SetCoordinates(xPostion, yPostion);
        }
        /// <summary>
        /// 清除所有的箭头
        /// </summary>
        private void RemoveArrow()
        {
            Graph.Annotations.RemoveAll();
        }
        /// <summary>
        /// 锚定指定的Maker
        /// </summary>
        /// <param name="name"></param>
        private void AnchoredMaker(string name)
        {
            Graph.Cursors.Item(name).SnapMode = CWUIControlsLib.CWCursorSnapModes.cwCSnapAnchoredToPoint;
            Graph.Cursors.Item(name).Plot = null;
        }
        /// <summary>
        /// 让被锚定的Maker继续可移动
        /// </summary>
        /// <param name="name"></param>
        private void FloatingMaker(string name)
        {
            Graph.Cursors.Item(name).SnapMode = CWUIControlsLib.CWCursorSnapModes.cwCSnapPointsOnPlot;
            Graph.Cursors.Item(name).Plot = Graph.Plots.Item(1);
        }
        /// <summary>
        /// 添加标志
        /// </summary>
        /// <param name="color">颜色</param>
        /// <param name="xPostion">x坐标</param>
        /// <param name="yPostion">y坐标</param>
        /// <param name="name"></param>
        private void AddMaker(uint color, object xPostion, object yPostion, string name)
        {
            Graph.TrackMode = CWUIControlsLib.CWGraphTrackModes.cwGTrackDragCursor;
            CWUIControlsLib.CWCursor cursor = Graph.Cursors.Add();
            cursor.Name = name;
            cursor.Color = color;
            cursor.PointStyle = CWUIControlsLib.CWPointStyles.cwPointBoldX;
            cursor.CrosshairStyle = CWUIControlsLib.CWCrosshairStyles.cwCrosshairMajorXMinorY;
            cursor.SnapMode = CWUIControlsLib.CWCursorSnapModes.cwCSnapFloating;
            cursor.XPosition = xPostion;
            cursor.YPosition = yPostion;
            cursor.Plot = Graph.Plots.Item("Plot-1");
            cursor.SnapMode = CWUIControlsLib.CWCursorSnapModes.cwCSnapPointsOnPlot;
        }
        /// <summary>
        /// 删除Maker
        /// </summary>
        private void RemoveMaker(string name)
        {
            Graph.Cursors.Remove(name);
        }
        /// <summary>
        /// 添加注释
        /// </summary>
        /// <param name="Caption">题目</param>
        /// <param name="x">x</param>
        /// <param name="y">y</param>
        /// <param name="name">名字</param>
        private void AddAnnotation(string Caption, double x, double y, string name, uint color)
        {
            CWUIControlsLib.CWAnnotation annotation = Graph.Annotations.Add();
            annotation.Caption.Text = Caption;
            annotation.Caption.Color = color;
            annotation.Arrow.Visible = false;
            annotation.Caption.XCoordinate = x;
            annotation.Caption.YCoordinate = y;
            annotation.Name = name;

        }
        /// <summary>
        /// 隐藏注释
        /// </summary>
        /// <param name="name">名字</param>
        private void RemoveAnnotation(string name)
        {
            Graph.Annotations.Remove(name);
        }
        #endregion


先写到这里 以后有想起啥 再来补充哈!
posted on 2007-11-15 13:41  王新路  阅读(1846)  评论(6编辑  收藏  举报