Exemplo n.º 1
0
        public void SetY3Scale()
        {
            Y2Axis yAxis3 = thePane.Y2AxisList[1];

            var y3CurveQuery = from curve in thePane.CurveList
                               where curve.IsY2Axis && curve.GetYAxisIndex(thePane) == 1
                               select curve;
            List <CurveItem> y3Curves = y3CurveQuery.ToList();

            if (y3Curves.Count == 0)
            {
                yAxis3.IsVisible = false;
                yAxis3.Scale.Max = 0.00001;
                yAxis3.Scale.Min = -0.00001;
            }
            else
            {
                yAxis3.IsVisible = true;
                //yAxis3.Scale.IsVisible = true;
                //yAxis3.Title.IsVisible = true;

                double max = 0;
                double xMin, xMax, yMin, yMax;

                foreach (CurveItem curve in y3Curves)
                {
                    curve.GetRange(out xMin, out xMax, out yMin, out yMax, false, false, thePane);
                    max = Math.Max(max, Math.Abs(yMin));
                    max = Math.Max(max, Math.Abs(yMax));
                }

                SetY3Scale(max);
            }
        }
Exemplo n.º 2
0
        private void SetYAxis(Y2Axis yAxis3, FontSpec YTitle, FontSpec YScale, CLSYAxisGroup cCur)
        {
            try
            {
                yAxis3.Title.Text           = cCur.Text;
                yAxis3.Title.FontSpec       = YTitle.Clone();
                yAxis3.Scale.FontSpec       = YScale.Clone();
                yAxis3.Scale.FontSpec.Angle = 270;

                yAxis3.Scale.FontSpec.FontColor = cCur.FontColor; //刻度字体颜色
                yAxis3.Title.FontSpec.FontColor = cCur.FontColor; //标题字体颜色
                yAxis3.MajorTic.Color           = GridColor;      //主网格刻度尺颜色
                yAxis3.Color               = GridColor;
                yAxis3.MinorTic.Color      = GridColor;           //次网格刻度尺颜色
                yAxis3.MajorGrid.IsVisible = true;                //是否显示主网格刻度线
                yAxis3.MajorGrid.Color     = GridColor;           //主网格刻度线颜色
                // turn off the opposite tics so the Y2 tics don't show up on the Y axis
                yAxis3.MajorTic.IsInside   = true;                // false;
                yAxis3.MinorTic.IsInside   = false;
                yAxis3.MajorTic.IsOpposite = false;
                yAxis3.MinorTic.IsOpposite = false;
                // Align the Y2 axis labels so they are flush to the axis
                yAxis3.Scale.Align   = AlignP.Inside;
                yAxis3.IsVisible     = true;
                yAxis3.Scale.Min     = cCur.ScaleMin;
                yAxis3.Scale.MinAuto = cCur.ScaleMinAuto;
                yAxis3.Scale.Max     = cCur.ScaleMax;
                yAxis3.Scale.MaxAuto = cCur.ScaleMaxAuto;
            }
            catch (Exception)
            { }
        }
Exemplo n.º 3
0
        public void SetY3Scale(double max)
        {
            Y2Axis yAxis3 = thePane.Y2AxisList[1];

            if (max == 0)
            {
                yAxis3.IsVisible = false;
                yAxis3.Scale.Max = 0.00001;
                yAxis3.Scale.Min = -0.00001;
                return;
            }

            yAxis3.Scale.Max = gracefulOf(Math.Abs(max), false);
            yAxis3.Scale.Min = -yAxis3.Scale.Max;

            double mag       = Math.Floor(Math.Log10(yAxis3.Scale.Max) - 1);
            Double step      = Math.Pow(10, mag);
            Double multiples = yAxis3.Scale.Max / step;

            if (multiples >= 50)
            {
                yAxis3.Scale.MinorStep = 5 * step;
                yAxis3.Scale.MajorStep = Math.Floor(multiples / 20) * 10 * step;
            }
            else if (multiples > 20)
            {
                yAxis3.Scale.MinorStep = 2 * step;
                yAxis3.Scale.MajorStep = Math.Floor(multiples / 10) * 5 * step;
            }
            else
            {
                yAxis3.Scale.MinorStep = step;
                yAxis3.Scale.MajorStep = Math.Floor(multiples / 10) * 5 * step;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 绘制标签(无图例影响的默认位置)
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tl"></param>
        /// <param name="lb"></param>
        /// <param name="y2a"></param>
        private void AddLabels(Graphics g, Title tl, XYLabel lb, Y2Axis y2a)
        {
            StringFormat sFormat = new StringFormat();

            sFormat.Alignment = StringAlignment.Center;

            SizeF      titleFontSize = g.MeasureString("A", tl.TitleStyle.TextFont);
            SolidBrush aBrush        = new SolidBrush(lb.XYLabelStyle.TextColor);
            //添加x轴标签
            SizeF labelFontSize = g.MeasureString("A", lb.XYLabelStyle.TextFont);

            if (lb.IsXLabelVisible)
            {
                if (string.IsNullOrWhiteSpace(lb.XLabel))
                {
                    lb.XLabel = "X Axis";
                }
                g.DrawString(lb.XLabel, lb.XYLabelStyle.TextFont, aBrush,
                             new Point(PlotArea.Left + PlotArea.Width / 2, ChartArea.Bottom - (int)YOffset - (int)labelFontSize.Height), sFormat);
            }

            //添加y轴标签
            if (lb.IsYLabelVisible)
            {
                if (string.IsNullOrWhiteSpace(lb.YLabel))
                {
                    lb.YLabel = "Y Axis";
                }
                // Save the state of the current Graphics object
                GraphicsState gState = g.Save();
                g.TranslateTransform(ChartArea.X + XOffset, ChartArea.Y + YOffset + titleFontSize.Height + YOffset / 2 + PlotArea.Height / 2);
                g.RotateTransform(-90);
                g.DrawString(lb.YLabel, lb.XYLabelStyle.TextFont, aBrush, new Point(0, 0), sFormat);
                // Restore it:
                g.Restore(gState);
            }

            //添加y2轴标签
            if (y2a.IsY2Axis)
            {
                if (lb.IsY2LabelVisible)
                {
                    if (string.IsNullOrWhiteSpace(lb.Y2Label))
                    {
                        lb.Y2Label = "Y2 Axis";
                    }
                    // Save the state of the current Graphics object
                    GraphicsState gState2 = g.Save();
                    g.TranslateTransform(ChartArea.X + ChartArea.Width - XOffset - labelFontSize.Width, ChartArea.Y + YOffset + titleFontSize.Height + YOffset / 2 + PlotArea.Height / 2);
                    g.RotateTransform(-90);
                    g.DrawString(lb.Y2Label, lb.XYLabelStyle.TextFont, aBrush, new Point(0, 0), sFormat);
                    // Restore it:
                    g.Restore(gState2);
                }
            }
            aBrush.Dispose();
        }
Exemplo n.º 5
0
        /// <summary>
        /// 绘制过程中以次纵坐标轴为准的坐标转换
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="xa"></param>
        /// <param name="y2a"></param>
        /// <returns></returns>
        internal PointF Point2DY2(PointF pt, XAxis xa, Y2Axis y2a)
        {
            PointF aPoint = new PointF();

            if (pt.X < xa.XLimMin || pt.X > xa.XLimMax || pt.Y < y2a.Y2LimMin || pt.Y > y2a.Y2LimMax)
            {
                pt.X = Single.NaN;
                pt.Y = Single.NaN;
            }
            aPoint.X = PlotArea.Left + (pt.X - xa.XLimMin) * PlotArea.Width / (xa.XLimMax - xa.XLimMin);
            aPoint.Y = PlotArea.Bottom - (pt.Y - y2a.Y2LimMin) * PlotArea.Height / (y2a.Y2LimMax - y2a.Y2LimMin);
            return(aPoint);
        }
Exemplo n.º 6
0
        private void SetupSecondaryAxes(IList <string> selected)
        {
            GraphPane myPane = zedChart.GraphPane;

            // Clear Y2AxisList so that when we re-add them, they'll all be 'reset' and in the right order
            myPane.Y2AxisList.Clear();

            // Add secondary axis as necessary to zedGraph
            foreach (string id in selected)
            {
                if (selected.Contains(id) && ColumnDefinition.GetTrackType(id) != ChartType)
                {
                    // Add new axis
                    int    yIndex = myPane.AddY2Axis(ColumnDefinition.GetText(id));
                    Y2Axis axis   = myPane.Y2AxisList[yIndex];
                    axis.Tag = id;

                    Color color = ColumnDefinition.GetTrackColor(id);
                    axis.Title.FontSpec.FontColor = color;
                    axis.Scale.FontSpec.FontColor = color;

                    axis.MajorGrid.IsVisible  = false;
                    axis.MajorGrid.Color      = myPane.XAxis.MajorGrid.Color;
                    axis.MajorGrid.DashOff    = myPane.XAxis.MajorGrid.DashOn;
                    axis.MajorGrid.DashOff    = myPane.YAxis.MajorGrid.DashOn;
                    axis.MajorGrid.IsZeroLine = false;
                    axis.IsAxisSegmentVisible = true;

                    axis.MinorTic.IsAllTics = false;
                    axis.MajorTic.IsAllTics = false;
                    axis.MajorTic.IsOutside = true;

                    // Setup Text Appearance
                    string fontName = "Microsoft Sans Sarif";
                    axis.Title.FontSpec.Family = fontName;
                    axis.Title.FontSpec.IsBold = true;
                    axis.Scale.FontSpec.Family = fontName;

                    axis.IsVisible = true;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 绘图控件初始化
        /// </summary>
        public void initZedGraph()
        {
            this._iSymbolType = 0;
            this._zedGraphOutputCurve.GraphPane.Border.IsVisible = false;

            this._zedGraphOutputCurve.Dock = DockStyle.Fill;
            this._zedGraphOutputCurve.GraphPane.LineNameLocation = enumLineNameLocation.None;
            this._zedGraphOutputCurve.GraphPane.Title.Text       = "";
            this._zedGraphOutputCurve.GraphPane.CurveList.Clear();

            YAxis  yAxis  = this._zedGraphOutputCurve.GraphPane.YAxisList[0].Clone();
            Y2Axis y2Axis = this._zedGraphOutputCurve.GraphPane.Y2AxisList[0].Clone();

            this._zedGraphOutputCurve.GraphPane.YAxisList.Clear();
            this._zedGraphOutputCurve.GraphPane.YAxisList.Add(yAxis);
            this._zedGraphOutputCurve.GraphPane.Y2AxisList.Clear();
            this._zedGraphOutputCurve.GraphPane.Y2AxisList.Add(y2Axis);

            this._zedGraphOutputCurve.GraphPane.Legend.Position = LegendPos.Bottom; //曲线名称的位置
            this._zedGraphOutputCurve.GraphPane.Legend.FontSpec = this.fontSpec;    //曲线名称的位置

            this._zedGraphOutputCurve.GraphPane.XAxis.MajorGrid.IsVisible = true;
            this._zedGraphOutputCurve.GraphPane.YAxis.MajorGrid.IsVisible = true;
            this._zedGraphOutputCurve.GraphPane.XAxis.MajorGrid.DashOff   = 3;
            this._zedGraphOutputCurve.GraphPane.YAxis.MajorGrid.DashOff   = 3;
            this._zedGraphOutputCurve.GraphPane.XAxis.MajorGrid.DashOn    = 3;
            this._zedGraphOutputCurve.GraphPane.YAxis.MajorGrid.DashOn    = 3;

            this._zedGraphOutputCurve.GraphPane.XAxis.MinorGrid.IsVisible = false;
            this._zedGraphOutputCurve.GraphPane.YAxis.MinorGrid.IsVisible = false;

            this._zedGraphOutputCurve.GraphPane.YAxis.MajorTic.IsOpposite  = false;
            this._zedGraphOutputCurve.GraphPane.YAxis.MinorTic.IsOpposite  = false;
            this._zedGraphOutputCurve.GraphPane.YAxis.MajorGrid.IsZeroLine = false;
            this._zedGraphOutputCurve.GraphPane.YAxis.Scale.Align          = AlignP.Inside;
        }
Exemplo n.º 8
0
        /// <summary>
        /// 绘制轴标签(受图例影响)
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tl"></param>
        /// <param name="lb"></param>
        /// <param name="y2a"></param>
        /// <param name="lg"></param>
        /// <param name="dcs"></param>
        private void AddLabels(Graphics g, Title tl, XYLabel lb, Y2Axis y2a, Legend lg, List <DataCollection> dcs)
        {
            StringFormat sFormat = new StringFormat();

            sFormat.Alignment = StringAlignment.Center;
            SolidBrush aBrush = new SolidBrush(lb.XYLabelStyle.TextColor);
            SizeF      labelFontSize = g.MeasureString("A", lb.XYLabelStyle.TextFont);
            float      stringX; float stringY;

            SizeF titleFontSize = g.MeasureString("A", tl.TitleStyle.TextFont);
            //图例对标题的影响
            float legendWidth = 0; float legendHeight = 0;

            if (lg.IsLegendVisible && !lg.IsInside)
            {
                lg.GetLegendSize(g, dcs, this, out legendWidth, out legendHeight);
            }

            //添加x轴标签
            if (lb.IsXLabelVisible)
            {
                if (string.IsNullOrWhiteSpace(lb.XLabel))
                {
                    lb.XLabel = "X Axis";
                }
                stringX = PlotArea.Left + PlotArea.Width / 2;
                stringY = ChartArea.Bottom - (int)YOffset - (int)labelFontSize.Height;
                if (lg.LegendPosition == Legend.LegendPositionEnum.South)
                {
                    stringY -= legendHeight;
                }
                g.DrawString(lb.XLabel, lb.XYLabelStyle.TextFont, aBrush, stringX, stringY, sFormat);
            }

            //添加y轴标签
            if (string.IsNullOrWhiteSpace(lb.YLabel))
            {
                lb.YLabel = "Y Axis";
            }
            stringX = ChartArea.X + XOffset;
            stringY = ChartArea.Y + YOffset + titleFontSize.Height + YOffset / 3 + PlotArea.Height / 2;
            if (lg.LegendPosition == Legend.LegendPositionEnum.West || lg.LegendPosition == Legend.LegendPositionEnum.SouthWest || lg.LegendPosition == Legend.LegendPositionEnum.NorthWest)
            {
                stringX += legendWidth;
            }
            if (lg.LegendPosition == Legend.LegendPositionEnum.North)
            {
                stringY += legendHeight;
            }
            // Save the state of the current Graphics object
            GraphicsState gState = g.Save();

            g.TranslateTransform(stringX, stringY);
            g.RotateTransform(-90);
            g.DrawString(lb.YLabel, lb.XYLabelStyle.TextFont, aBrush, 0, 0, sFormat);
            // Restore it:
            g.Restore(gState);

            //添加y2轴标签
            if (y2a.IsY2Axis)
            {
                if (string.IsNullOrWhiteSpace(lb.Y2Label))
                {
                    lb.Y2Label = "Y2 Axis";
                }
                stringX = ChartArea.X + ChartArea.Width - XOffset - labelFontSize.Height;
                stringY = ChartArea.Y + YOffset + titleFontSize.Height + YOffset / 3 + PlotArea.Height / 2;
                if (lg.LegendPosition == Legend.LegendPositionEnum.East || lg.LegendPosition == Legend.LegendPositionEnum.SouthEast || lg.LegendPosition == Legend.LegendPositionEnum.NorthEast)
                {
                    stringX -= legendWidth;
                }
                if (lg.LegendPosition == Legend.LegendPositionEnum.North)
                {
                    stringY += legendHeight;
                }
                // Save the state of the current Graphics object
                GraphicsState gState2 = g.Save();
                g.TranslateTransform(stringX, stringY);
                g.RotateTransform(-90);
                g.DrawString(lb.Y2Label, lb.XYLabelStyle.TextFont, aBrush, 0, 0, sFormat);

                // Restore it:
                g.Restore(gState2);
            }
            aBrush.Dispose();
        }
Exemplo n.º 9
0
        /// <summary>
        /// 设置直角坐标绘图区位置、大小(受元素之间的相互影响)
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tl"></param>
        /// <param name="lb"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        /// <param name="y2a"></param>
        /// <param name="gd"></param>
        /// <param name="lg"></param>
        /// <param name="dcs"></param>
        private void SetPlotArea(Graphics g, Title tl, XYLabel lb, XAxis xa, YAxis ya, Y2Axis y2a, Grid gd, Legend lg, List <DataCollection> dcs)
        {
            SizeF titleFontSize = g.MeasureString("A", tl.TitleStyle.TextFont);

            if (string.IsNullOrWhiteSpace(tl.TitleName) || tl.TitleName.ToUpper() == "NO TITLE")
            {
                titleFontSize.Width  = 8f;
                titleFontSize.Height = 8f;
            }
            float xSpacing      = XOffset / 2.0f;
            float ySpacing      = YOffset / 2.0f;
            SizeF labelFontSize = g.MeasureString("A", lb.XYLabelStyle.TextFont);
            SizeF tickFontSize  = g.MeasureString("A", xa.XTickStyle.TextFont);
            float tickSpacing   = 2f;

            //图例所在位置影响plotarea的大小和位置
            #region  受图例影响时
            if (!lg.IsLegendVisible || lg.IsInside)
            {
                //X轴标记的自适应和全显示,影响底部间距
                //float bottomMargin = YOffset + xlabelFontSize.Height + ySpacing + tickFontSize.Height + tickSpacing;
                float bottomMargin = YOffset + tickSpacing + ySpacing;
                if (lb.IsXLabelVisible)
                {
                    bottomMargin += labelFontSize.Height;
                }

                SizeF xTickSize = g.MeasureString(xa.XLimMin.ToString(), xa.XTickStyle.TextFont);
                int   xcount    = (int)Math.Round((xa.XLimMax - xa.XLimMin) / xa.XTick) + 1;
                for (int i = 0; i < xcount; i++)
                {
                    SizeF tempSize = g.MeasureString(xa.XTickMarkFull[i], xa.XTickStyle.TextFont);
                    if (xTickSize.Width < tempSize.Width)
                    {
                        xTickSize = tempSize;
                    }
                }
                if (xa.XTickAngle == 0)
                {
                    bottomMargin += xTickSize.Height;
                }
                else if (xa.XTickAngle == -90)
                {
                    bottomMargin += xTickSize.Width;
                }
                else
                {
                    bottomMargin += xTickSize.Width * 0.72f;
                }


                //获取y轴标记宽度
                SizeF yTickSize = g.MeasureString(ya.YLimMin.ToString(), ya.YTickStyle.TextFont);
                int   ycount    = (int)Math.Round((ya.YLimMax - ya.YLimMin) / ya.YTick) + 1;
                for (int i = 0; i < ycount; i++)
                {
                    float yTick    = ya.YLimMin + i * ya.YTick;
                    SizeF tempSize = g.MeasureString(yTick.ToString(), ya.YTickStyle.TextFont);
                    if (yTickSize.Width < tempSize.Width)
                    {
                        yTickSize = tempSize;
                    }
                }
                float leftMargin  = XOffset + labelFontSize.Height + xSpacing + yTickSize.Width + tickSpacing;
                float rightMargin = 2 * XOffset;
                float topMargin   = YOffset + titleFontSize.Height + ySpacing;

                //单y轴绘图区
                int plotX      = ChartArea.X + (int)leftMargin;
                int plotY      = ChartArea.Y + (int)topMargin;
                int plotHeight = ChartArea.Height - (int)topMargin - (int)bottomMargin;
                int plotWidth  = ChartArea.Width - (int)leftMargin - (int)rightMargin;

                //双y轴:重新定义绘图区宽度
                if (y2a.IsY2Axis)
                {
                    //y2轴标记宽度
                    SizeF y2TickSize = g.MeasureString(y2a.Y2LimMin.ToString(), y2a.Y2TickStyle.TextFont);
                    int   y2count    = (int)Math.Round((y2a.Y2LimMax - y2a.Y2LimMin) / y2a.Y2Tick) + 1;
                    for (int i = 0; i < y2count; i++)
                    {
                        float y2Tick    = y2a.Y2LimMin + i * y2a.Y2Tick;
                        SizeF tempSize2 = g.MeasureString(y2Tick.ToString(), y2a.Y2TickStyle.TextFont);
                        if (y2TickSize.Width < tempSize2.Width)
                        {
                            y2TickSize = tempSize2;
                        }
                    }
                    rightMargin = XOffset + labelFontSize.Height + xSpacing + y2TickSize.Width + tickSpacing;
                    plotWidth   = ChartArea.Width - (int)leftMargin - (int)rightMargin;
                }
                plotArea = new Rectangle(plotX, plotY, plotWidth, plotHeight);
            }
            #endregion
            #region 外部图例
            else
            {
                //X轴标记的自适应和全显示,影响底部间距bottom
                float bottomMargin = YOffset + tickSpacing + ySpacing;
                if (lb.IsXLabelVisible)
                {
                    bottomMargin += labelFontSize.Height;
                }

                SizeF xTickSize = g.MeasureString(xa.XLimMin.ToString(), xa.XTickStyle.TextFont);
                int   count     = (int)Math.Round((xa.XLimMax - xa.XLimMin) / xa.XTick) + 1;
                for (int i = 0; i < count; i++)
                {
                    SizeF tempSize = g.MeasureString(xa.XTickMarkFull[i], xa.XTickStyle.TextFont);
                    if (xTickSize.Width < tempSize.Width)
                    {
                        xTickSize = tempSize;
                    }
                }
                if (xa.XTickAngle == 0)
                {
                    bottomMargin += xTickSize.Height;
                }
                else if (xa.XTickAngle == -90)
                {
                    bottomMargin += xTickSize.Width;
                }
                else
                {
                    bottomMargin += xTickSize.Width * 0.72f;
                }

                //获取y轴标记宽度
                SizeF yTickSize = g.MeasureString(ya.YLimMin.ToString(), ya.YTickStyle.TextFont);
                int   ycount    = (int)Math.Round((ya.YLimMax - ya.YLimMin) / ya.YTick) + 1;
                for (int i = 0; i < ycount; i++)
                {
                    float yTick    = ya.YLimMin + i * ya.YTick;
                    SizeF tempSize = g.MeasureString(yTick.ToString(), ya.YTickStyle.TextFont);
                    if (yTickSize.Width < tempSize.Width)
                    {
                        yTickSize = tempSize;
                    }
                }
                float leftMargin  = XOffset + labelFontSize.Height + xSpacing + yTickSize.Width + tickSpacing;
                float rightMargin = XOffset + xSpacing;
                float topMargin   = YOffset + titleFontSize.Height + ySpacing;

                //根据图例位置确定边距
                float legendWidth = 0; float legendHeight = 0;
                lg.GetLegendSize(g, dcs, this, out legendWidth, out legendHeight);
                if (lg.LegendPosition == Legend.LegendPositionEnum.East || lg.LegendPosition == Legend.LegendPositionEnum.SouthEast || lg.LegendPosition == Legend.LegendPositionEnum.NorthEast)
                {
                    rightMargin += legendWidth;
                }
                if (lg.LegendPosition == Legend.LegendPositionEnum.West || lg.LegendPosition == Legend.LegendPositionEnum.SouthWest || lg.LegendPosition == Legend.LegendPositionEnum.NorthWest)
                {
                    leftMargin += legendWidth;
                }
                if (lg.LegendPosition == Legend.LegendPositionEnum.North)
                {
                    topMargin += legendHeight;
                }
                if (lg.LegendPosition == Legend.LegendPositionEnum.South)
                {
                    bottomMargin += legendHeight;
                }

                //单y轴绘图区大小
                int plotX      = ChartArea.X + (int)leftMargin;
                int plotY      = ChartArea.Y + (int)topMargin;
                int plotHeight = ChartArea.Height - (int)topMargin - (int)bottomMargin;
                int plotWidth  = ChartArea.Width - (int)leftMargin - (int)rightMargin;

                //双y轴:重新定义绘图区宽度
                if (y2a.IsY2Axis)
                {
                    //y2轴标记宽度
                    SizeF y2TickSize = g.MeasureString(y2a.Y2LimMin.ToString(), y2a.Y2TickStyle.TextFont);
                    int   y2count    = (int)Math.Round((y2a.Y2LimMax - y2a.Y2LimMin) / y2a.Y2Tick) + 1;
                    for (int i = 0; i < y2count; i++)
                    {
                        float y2Tick    = y2a.Y2LimMin + i * y2a.Y2Tick;
                        SizeF tempSize2 = g.MeasureString(y2Tick.ToString(), y2a.Y2TickStyle.TextFont);
                        if (y2TickSize.Width < tempSize2.Width)
                        {
                            y2TickSize = tempSize2;
                        }
                    }
                    rightMargin = XOffset + labelFontSize.Height + xSpacing + y2TickSize.Width + tickSpacing;

                    if (lg.LegendPosition == Legend.LegendPositionEnum.East || lg.LegendPosition == Legend.LegendPositionEnum.SouthEast || lg.LegendPosition == Legend.LegendPositionEnum.NorthEast)
                    {
                        rightMargin += legendWidth;
                    }
                    plotWidth = ChartArea.Width - (int)leftMargin - (int)rightMargin;
                }
                plotArea = new Rectangle(plotX, plotY, plotWidth, plotHeight);
            }
            #endregion
        }
Exemplo n.º 10
0
        /// <summary>
        /// 直角坐标样式布局
        /// </summary>
        /// <param name="g"></param>
        /// <param name="dcs"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        /// <param name="y2a"></param>
        /// <param name="gd"></param>
        /// <param name="lb"></param>
        /// <param name="tl"></param>
        /// <param name="lg"></param>
        internal void AddChartStyleSquare(Graphics g, Title tl, XYLabel lb, Grid gd, XAxis xa, YAxis ya, Y2Axis y2a, Legend lg, List <DataCollection> dcs)
        {
            try
            {
                //设置直角坐标绘图区位置、大小(受元素之间的相互影响)
                SetPlotArea(g, tl, lb, xa, ya, y2a, gd, lg, dcs);
                //再次确定大小的原因:根据plot宽度->确定文本角度->重新确定plot高度
                AxisFit.SetTickAngle(g, this, lb, xa);
                SetPlotArea(g, tl, lb, xa, ya, y2a, gd, lg, dcs);

                //ChartArea和PlotArea底色绘制(通用)
                FillColorInChartAreas(g);
                //绘制标题(通用)
                AddTitle(g, tl);
                //直角坐标通用网格线
                AddGirdSquare(g, gd, xa, ya);

                //绘制轴标签(受图例影响)
                AddLabels(g, tl, lb, y2a, lg, dcs);
                //绘制坐标轴刻度线和标记(受数据影响)
                AddTicks(g, lb, xa, ya, y2a);
            }
            catch { }
        }
Exemplo n.º 11
0
        public void Zed()
        {
            GraphPane myPane = zed.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text       = "Mõõtetulemused";
            myPane.XAxis.Title.Text = "Time, ms";

            myPane.Y2Axis.Title.Text = "Tõmme, N";
            myPane.YAxis.Title.Text  = "Vääne, N";

            // Generate a red curve with diamond symbols, and "Velocity" in the legend
            LineItem myCurve = myPane.AddCurve("Vääne",
                                               TorquePoints, Color.Red, SymbolType.None);

            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Generate a blue curve with circle symbols, and "Acceleration" in the legend
            myCurve = myPane.AddCurve("Tõmme",
                                      PullPoints, Color.Blue, SymbolType.None);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;

            // Generate a green curve with square symbols, and "Distance" in the legend
            myCurve = myPane.AddCurve("Temperatuur",
                                      TempPoints, Color.Green, SymbolType.None);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 1;

            // Generate a Black curve with triangle symbols, and "Energy" in the legend
            myCurve = myPane.AddCurve("RPM",
                                      RPMPoints, Color.DarkOrange, SymbolType.None);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;
            // Associate this curve with the second Y2 axis
            myCurve.YAxisIndex = 1;

            myPane.YAxis.Type = AxisType.Linear;

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max   = 100;

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            //myPane.Y2Axis.Scale.Min = 1.5;
            myPane.Y2Axis.Scale.Max = 100;

            // Create a second Y Axis, green
            YAxis yAxis3 = new YAxis("Temperatuur, °C");

            myPane.YAxisList.Add(yAxis3);
            yAxis3.Scale.FontSpec.FontColor = Color.Green;
            yAxis3.Title.FontSpec.FontColor = Color.Green;
            yAxis3.Color = Color.Green;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis3.MajorTic.IsInside   = false;
            yAxis3.MinorTic.IsInside   = false;
            yAxis3.MajorTic.IsOpposite = false;
            yAxis3.MinorTic.IsOpposite = false;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis3.Scale.Align = AlignP.Inside;
            yAxis3.Scale.Max   = 100;

            Y2Axis yAxis4 = new Y2Axis("RPM, p/min");

            yAxis4.IsVisible = true;
            myPane.Y2AxisList.Add(yAxis4);
            yAxis4.Scale.FontSpec.FontColor = Color.DarkOrange;
            yAxis4.Title.FontSpec.FontColor = Color.DarkOrange;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis4.MajorTic.IsInside   = false;
            yAxis4.MinorTic.IsInside   = false;
            yAxis4.MajorTic.IsOpposite = false;
            yAxis4.MinorTic.IsOpposite = false;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis4.Scale.Align = AlignP.Inside;
            yAxis4.Type        = AxisType.Linear;
            yAxis4.Scale.Max   = 100;

            // Fill the axis background with a gradient
            // myPane.Chart.Fill = new Fill(Color.Gray, Color.Black, 45.0f);

            myPane.Chart.Fill = new Fill(Color.WhiteSmoke);

            // Tell ZedGraph to calculate the axis ranges
            // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
            // up the proper scrolling parameters
            zed.AxisChange();
            // Make sure the Graph gets redrawn
            zed.Invalidate();
        }
Exemplo n.º 12
0
        /// <summary>
        /// 设置默认绘图区位置,大小(无图例影响的默认位置)
        /// </summary>
        /// <param name="g"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        /// <param name="y2a"></param>
        /// <param name="gd"></param>
        /// <param name="lb"></param>
        /// <param name="tl"></param>
        private void SetPlotArea(Graphics g, Title tl, XYLabel lb, Grid gd, XAxis xa, YAxis ya, Y2Axis y2a)
        {
            SizeF titleFontSize = g.MeasureString("A", tl.TitleStyle.TextFont);

            if (string.IsNullOrWhiteSpace(tl.TitleName) || tl.TitleName.ToUpper() == "NO TITLE")
            {
                titleFontSize.Width  = 8f;
                titleFontSize.Height = 8f;
            }
            float xSpacing     = XOffset / 2.0f;
            float ySpacing     = YOffset / 2.0f;
            SizeF tickFontSize = g.MeasureString("A", xa.XTickStyle.TextFont);
            float tickSpacing  = 2f;

            //获取y轴标记宽度
            SizeF yTickSize = g.MeasureString(ya.YLimMin.ToString(), ya.YTickStyle.TextFont);
            int   ycount    = (int)Math.Round((ya.YLimMax - ya.YLimMin) / ya.YTick) + 1;

            for (int i = 0; i < ycount; i++)
            {
                float yTick = ya.YLimMin + i * ya.YTick;
                yTick = DataDeal.FloatAccur(yTick);
                SizeF tempSize = g.MeasureString(yTick.ToString(), ya.YTickStyle.TextFont);
                if (yTickSize.Width < tempSize.Width)
                {
                    yTickSize = tempSize;
                }
            }
            SizeF labelFontSize = g.MeasureString("A", lb.XYLabelStyle.TextFont);
            float leftMargin    = XOffset + labelFontSize.Height + xSpacing + yTickSize.Width + tickSpacing;
            float rightMargin   = 2 * XOffset;
            float topMargin     = YOffset + titleFontSize.Height + ySpacing;
            float bottomMargin  = YOffset + labelFontSize.Height + ySpacing + tickFontSize.Height + tickSpacing;

            //单y轴绘图区大小
            int plotX      = ChartArea.X + (int)leftMargin;
            int plotY      = ChartArea.Y + (int)topMargin;
            int plotHeight = ChartArea.Height - (int)topMargin - (int)bottomMargin;
            int plotWidth  = ChartArea.Width - (int)leftMargin - (int)rightMargin;

            //双y轴:重新定义绘图区宽度
            if (y2a.IsY2Axis)
            {
                //y2轴标记宽度
                SizeF y2TickSize = g.MeasureString(y2a.Y2LimMin.ToString(), y2a.Y2TickStyle.TextFont);
                int   y2count    = (int)Math.Round((y2a.Y2LimMax - y2a.Y2LimMin) / y2a.Y2Tick) + 1;
                for (int i = 0; i < ycount; i++)
                {
                    float y2Tick = y2a.Y2LimMin + i * y2a.Y2Tick;
                    y2Tick = DataDeal.FloatAccur(y2Tick);
                    SizeF tempSize2 = g.MeasureString(y2Tick.ToString(), y2a.Y2TickStyle.TextFont);
                    if (y2TickSize.Width < tempSize2.Width)
                    {
                        y2TickSize = tempSize2;
                    }
                }
                rightMargin = XOffset + labelFontSize.Height + xSpacing + y2TickSize.Width + tickSpacing;
                plotWidth   = ChartArea.Width - (int)leftMargin - (int)rightMargin;
            }
            plotArea = new Rectangle(plotX, plotY, plotWidth, plotHeight);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 初始化图表控件
        /// </summary>
        public void chart_initial()
        {
            zedGraphControl1.IsShowContextMenu = false;
            zedGraphControl1.IsEnableHPan      = false; zedGraphControl1.IsEnableVPan = false;
            zedGraphControl1.IsEnableHZoom     = false; zedGraphControl1.IsEnableZoom = false;
            GraphPane myPane = zedGraphControl1.GraphPane;

            // myPane.Fill = new Fill(Color.FromArgb(28, 29, 31));
            myPane.Fill               = new Fill(Color.Black);
            myPane.Chart.Fill         = new Fill(Color.Black);
            myPane.IsFontsScaled      = false;
            myPane.Border.Color       = Color.White;
            myPane.Chart.Border.Color = Color.Gray;
            // Set the titles and axis labels
            myPane.Legend.IsVisible = false;
            myPane.Title.Text       = " ";
            //x轴
            myPane.XAxis.Title.Text               = "时间(分钟)";
            myPane.XAxis.MajorGrid.Color          = Color.White;
            myPane.XAxis.Scale.FontSpec.FontColor = Color.White;
            myPane.XAxis.Scale.FontSpec.Size      = 15;
            myPane.XAxis.Title.FontSpec.Size      = 15;
            myPane.XAxis.Title.FontSpec.FontColor = Color.White;
            myPane.XAxis.Scale.Min           = 0;  //X轴最小值0
            myPane.XAxis.Scale.Max           = 30; //X轴最大30
            myPane.XAxis.MajorTic.IsInside   = false;
            myPane.XAxis.MinorTic.IsInside   = false;
            myPane.XAxis.MajorTic.IsOpposite = false;
            myPane.XAxis.MinorTic.IsOpposite = false;
            myPane.XAxis.MajorTic.Color      = Color.White;
            myPane.XAxis.MinorTic.Color      = Color.White;
            myPane.XAxis.Scale.MajorStep     = 5;//X轴大步长为5,也就是显示文字的大间隔
            myPane.XAxis.MajorGrid.IsVisible = true;
            //y轴
            myPane.YAxis.MajorTic.IsInside  = false;
            myPane.YAxis.MajorGrid.Color    = Color.White;
            myPane.YAxis.MinorTic.IsInside  = false;
            myPane.Y2Axis.MajorTic.IsInside = false;
            myPane.Y2Axis.MajorGrid.Color   = Color.White;
            myPane.Y2Axis.MinorTic.IsInside = false;

            // Make up some data points based on the Sine function
            PointPairList List1 = new PointPairList();
            PointPairList List2 = new PointPairList();
            PointPairList List3 = new PointPairList();
            PointPairList List4 = new PointPairList();
            PointPairList List5 = new PointPairList();
            PointPairList List6 = new PointPairList();


            // 根据配置信息,生成曲线坐标轴的样式
            LineItem myCurve = myPane.AddCurve(paraLine3.Tagname,
                                               List1, paraLine3.Color, SymbolType.None);

            myCurve.Line.Width = 1;

            myCurve = myPane.AddCurve(paraLine4.Tagname,
                                      List2, paraLine4.Color, SymbolType.None);
            myCurve.Line.Width = 1;
            myCurve.IsY2Axis   = true;


            myCurve = myPane.AddCurve(paraLine2.Tagname,
                                      List3, paraLine2.Color, SymbolType.None);
            myCurve.Line.Width = 1;
            myCurve.YAxisIndex = 1;

            myCurve = myPane.AddCurve(paraLine5.Tagname,
                                      List4, paraLine5.Color, SymbolType.None);
            myCurve.Line.Width = 1;
            myCurve.IsY2Axis   = true;
            myCurve.YAxisIndex = 1;

            myCurve = myPane.AddCurve(paraLine1.Tagname,
                                      List5, paraLine1.Color, SymbolType.None);
            myCurve.Line.Width = 1;
            myCurve.YAxisIndex = 2;

            myCurve = myPane.AddCurve(paraLine6.Tagname,
                                      List6, paraLine6.Color, SymbolType.None);
            myCurve.Line.Width = 1;
            myCurve.IsY2Axis   = true;
            myCurve.YAxisIndex = 2;

            // Make the Y axis
            myPane.YAxis.Scale.FontSpec.FontColor = paraLine3.Color;
            myPane.YAxis.Scale.FontSpec.Size      = 15;
            myPane.YAxis.Title.FontSpec.FontColor = paraLine3.Color;
            myPane.YAxis.Title.FontSpec.Size      = 15;
            myPane.YAxis.Color = paraLine3.Color;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MajorTic.Color      = paraLine3.Color;
            myPane.YAxis.MinorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.Color      = paraLine3.Color;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max   = int.Parse(paraLine3.Max);
            myPane.YAxis.Scale.Min   = int.Parse(paraLine3.Min);

            // Enable the Y2 axis
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale black
            myPane.Y2Axis.Scale.FontSpec.FontColor = paraLine4.Color;
            myPane.Y2Axis.Scale.FontSpec.Size      = 15;
            myPane.Y2Axis.Title.FontSpec.FontColor = paraLine4.Color;
            myPane.Y2Axis.Title.FontSpec.Size      = 15;
            myPane.Y2Axis.Color = paraLine4.Color;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MajorTic.Color      = paraLine4.Color;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.Color      = paraLine4.Color;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            myPane.Y2Axis.Scale.Max   = int.Parse(paraLine4.Max);
            myPane.Y2Axis.Scale.Min   = int.Parse(paraLine4.Min);

            // Create a second Y Axis
            YAxis yAxis3 = new YAxis(paraLine2.Tagname + "(" + paraLine2.Unit + ")");

            myPane.YAxisList.Add(yAxis3);
            yAxis3.Scale.FontSpec.FontColor = paraLine2.Color;
            yAxis3.Scale.FontSpec.Size      = 15;
            yAxis3.Title.FontSpec.FontColor = paraLine2.Color;
            yAxis3.Title.FontSpec.Size      = 15;
            yAxis3.Color = paraLine2.Color;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis3.MajorTic.IsInside   = false;
            yAxis3.MinorTic.IsInside   = false;
            yAxis3.MajorTic.IsOpposite = false;
            yAxis3.MajorTic.Color      = paraLine2.Color;
            yAxis3.MinorTic.IsOpposite = false;
            yAxis3.MinorTic.Color      = paraLine2.Color;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis3.Scale.Align = AlignP.Inside;
            yAxis3.Scale.Max   = int.Parse(paraLine2.Max);
            yAxis3.Scale.Min   = int.Parse(paraLine2.Min);


            // Create a third Y Axis
            YAxis yAxis5 = new YAxis(paraLine1.Tagname + "(" + paraLine1.Unit + ")");

            myPane.YAxisList.Add(yAxis5);
            yAxis5.Scale.FontSpec.FontColor = paraLine1.Color;
            yAxis5.Scale.FontSpec.Size      = 15;
            yAxis5.Title.FontSpec.FontColor = paraLine1.Color;
            yAxis5.Title.FontSpec.Size      = 15;
            yAxis5.Color = paraLine1.Color;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis5.MajorTic.IsInside   = false;
            yAxis5.MinorTic.IsInside   = false;
            yAxis5.MajorTic.IsOpposite = false;
            yAxis5.MajorTic.Color      = paraLine1.Color;
            yAxis5.MinorTic.IsOpposite = false;
            yAxis5.MinorTic.Color      = paraLine1.Color;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis5.Scale.Align = AlignP.Inside;
            yAxis5.Scale.Max   = int.Parse(paraLine1.Max);
            yAxis5.Scale.Min   = int.Parse(paraLine1.Min);


            // Create a second Y2 Axis
            Y2Axis yAxis4 = new Y2Axis(paraLine5.Tagname + "(" + paraLine5.Unit + ")");

            yAxis4.IsVisible = true;
            myPane.Y2AxisList.Add(yAxis4);
            yAxis4.Scale.FontSpec.FontColor = paraLine5.Color;
            yAxis4.Scale.FontSpec.Size      = 15;
            yAxis4.Title.FontSpec.FontColor = paraLine5.Color;
            yAxis4.Title.FontSpec.Size      = 15;
            yAxis4.Color = paraLine5.Color;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis4.MajorTic.IsInside   = false;
            yAxis4.MinorTic.IsInside   = false;
            yAxis4.MajorTic.IsOpposite = false;
            yAxis4.MajorTic.Color      = paraLine5.Color;
            yAxis4.MinorTic.IsOpposite = false;
            yAxis4.MinorTic.Color      = paraLine5.Color;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis4.Scale.Align = AlignP.Inside;
            yAxis4.Scale.Max   = int.Parse(paraLine5.Max);
            yAxis4.Scale.Min   = int.Parse(paraLine5.Min);

            // Create a third Y2 Axis
            Y2Axis yAxis6 = new Y2Axis(paraLine6.Tagname + "(" + paraLine6.Unit + ")");

            yAxis6.IsVisible = true;
            myPane.Y2AxisList.Add(yAxis6);
            yAxis6.Scale.FontSpec.FontColor = paraLine6.Color;
            yAxis6.Scale.FontSpec.Size      = 15;
            yAxis6.Title.FontSpec.FontColor = paraLine6.Color;
            yAxis6.Title.FontSpec.Size      = 15;
            yAxis6.Color = paraLine6.Color;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis6.MajorTic.IsInside   = false;
            yAxis6.MinorTic.IsInside   = false;
            yAxis6.MajorTic.IsOpposite = false;
            yAxis6.MajorTic.Color      = paraLine6.Color;
            yAxis6.MinorTic.IsOpposite = false;
            yAxis6.MinorTic.Color      = paraLine6.Color;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis6.Scale.Align = AlignP.Inside;
            yAxis6.Scale.Max   = int.Parse(paraLine6.Max);
            yAxis6.Scale.Min   = int.Parse(paraLine6.Min);
            // Fill the axis background with a gradient
            //  myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);


            //新增,y轴不显示名称及零线
            foreach (YAxis y in myPane.YAxisList)
            {
                y.MajorGrid.IsZeroLine = false;
                y.Title.IsVisible      = false;
            }
            foreach (Y2Axis y in myPane.Y2AxisList)
            {
                y.MajorGrid.IsZeroLine = false;
                y.Title.IsVisible      = false;
            }
            //新增,读取配置文件的曲线颜色信息,更新曲线
            trend_refresh("1"); trend_refresh("2"); trend_refresh("3");
            trend_refresh("4"); trend_refresh("5"); trend_refresh("6");
            trend_refresh(paraLine1.checkBox1.Checked, "1"); trend_refresh(paraLine4.checkBox1.Checked, "4");
            trend_refresh(paraLine2.checkBox1.Checked, "2"); trend_refresh(paraLine5.checkBox1.Checked, "5");
            trend_refresh(paraLine3.checkBox1.Checked, "3"); trend_refresh(paraLine6.checkBox1.Checked, "6");

            zedGraphControl1.AxisChange();
        }
Exemplo n.º 14
0
        internal static void AddAreas(DataCollectionArea dc, Graphics g, ChartStyle cs, XAxis xa, YAxis ya, Y2Axis y2a)
        {
            if (dc.ChartType != Chart2DTypeEnum.AreaChart || dc.DataSeriesList.Count == 0)
            {
                return;
            }

            //比较各列点数,面积图需统一点数(暂不处理,待优化:以最少点数为准)
            int  nPoints      = 0;
            bool isConsistant = true;
            bool isY2         = false;

            foreach (DataSeries ds in dc.DataSeriesList)
            {
                if (nPoints == 0)
                {
                    nPoints = ds.PointList.Count;
                }
                else if (nPoints != ds.PointList.Count)
                {
                    isConsistant = false;
                }
                if (ds.IsY2Data)
                {
                    isY2 = true;
                }
            }
            if (!isConsistant)
            {
                return;
            }

            float[]  ySum = new float[nPoints];
            PointF[] pts  = new PointF[2 * nPoints];
            PointF[] pt0  = new PointF[nPoints];
            PointF[] pt1  = new PointF[nPoints];
            for (int i = 0; i < nPoints; i++)
            {
                ySum[i] = dc.AreaAxis;
            }

            int        n      = 0;
            Pen        aPen   = new Pen(Color.Black);
            SolidBrush aBrush = new SolidBrush(Color.Black);

            foreach (DataSeries ds in dc.DataSeriesList)
            {
                //Color fillColor = Color.FromArgb(dc.CMap[n, 0], dc.CMap[n, 1], dc.CMap[n, 2], dc.CMap[n, 3]);
                if (ds.FillColor != Color.Empty)
                {
                    aBrush = new SolidBrush(ds.FillColor);
                }
                else
                {
                    aBrush = new SolidBrush(Color.FromArgb(180, ds.LineStyle.LineColor));
                }
                aPen           = new Pen(ds.LineStyle.LineColor, ds.LineStyle.LineThickness);
                aPen.DashStyle = ds.LineStyle.LinePattern;

                // Draw lines and areas:
                if (dc.AreaChartType == AreaChartTypeEnum.Area)
                {
                    if (!isY2)
                    {
                        for (int i = 0; i < nPoints; i++)
                        {
                            pt0[i]  = new PointF(((PointF)ds.PointList[i]).X, ySum[i]);
                            ySum[i] = ySum[i] + ((PointF)ds.PointList[i]).Y;
                            pt1[i]  = new PointF(((PointF)ds.PointList[i]).X, ySum[i]);
                            pts[i]  = cs.Point2D(pt0[i], xa, ya);
                            pts[2 * nPoints - 1 - i] = cs.Point2D(pt1[i], xa, ya);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < nPoints; i++)
                        {
                            pt0[i]  = new PointF(((PointF)ds.PointList[i]).X, ySum[i]);
                            ySum[i] = ySum[i] + ((PointF)ds.PointList[i]).Y;
                            pt1[i]  = new PointF(((PointF)ds.PointList[i]).X, ySum[i]);
                            pts[i]  = cs.Point2DY2(pt0[i], xa, y2a);
                            pts[2 * nPoints - 1 - i] = cs.Point2DY2(pt1[i], xa, y2a);
                        }
                    }
                    g.FillPolygon(aBrush, pts);
                    if (ds.LineStyle.IsVisible)
                    {
                        g.DrawPolygon(aPen, pts);
                    }
                    n++;
                }
            }
            aPen.Dispose();
            aBrush.Dispose();
        }
Exemplo n.º 15
0
        public void DrawYAxis()
        {
            myPane.CurveList.Clear();
            if (SelTream.ListYAxisGroup.Count < 1)
            {
                zedG.AxisChange();
                zedG.Refresh();
                return;
            }
            myPane.XAxis.Title.Text = XAxisTitle;
            for (int i = 0; i < SelTream.ListYAxisGroup.Count; i++)
            {
                CLSYAxisGroup cCur = SelTream.ListYAxisGroup[i];
                if (i == 0)
                {
                    // Make the Y axis scale red
                    SetYAxis(myPane.YAxis, AxisYTitle.FontSpec, AxisYScale.FontSpec, cCur);
                }
                else if (i == 1)
                {
                    SetYAxis(myPane.Y2Axis, AxisYTitle.FontSpec, AxisYScale.FontSpec, cCur);
                }
                else if (i % 2 == 0)
                {
                    YAxis yAxis3 = new YAxis(cCur.Text);
                    SetYAxis(yAxis3, AxisYTitle.FontSpec, AxisYScale.FontSpec, cCur);
                    myPane.YAxisList.Add(yAxis3);
                }
                else if (i % 2 == 1)
                {
                    Y2Axis yAxis3 = new Y2Axis(cCur.Text);
                    SetYAxis(yAxis3, AxisYTitle.FontSpec, AxisYScale.FontSpec, cCur);
                    myPane.Y2AxisList.Add(yAxis3);
                }
                else
                {
                    return;
                }

                int i1 = i % 2;
                int i2 = i / 2;

                foreach (CLSCurve nCur in cCur.ListCur)
                {
                    LineItem myCurve = myPane.AddCurve(nCur.Text, nCur.ListPT, nCur.LineColor, SymbolType.None);
                    myCurve.Symbol.Size = 10;
                    myCurve.Line.Width  = CurveLineWith;
                    //myCurve.Line.Style = DashStyle.DashDotDot;
                    // Fill the symbols with white
                    //myCurve.Symbol.Fill = new Fill(Color.White);
                    myCurve.YAxisIndex = i2;
                    if (i1 == 1)
                    {
                        // Associate this curve with the Y2 axis
                        myCurve.IsY2Axis = true;
                    }
                }
            }

            zedG.AxisChange();
            zedG.Refresh();
        }
Exemplo n.º 16
0
        public void InitiateGraphControl()
        {
            Zed.IsShowVScrollBar  = false;
            Zed.IsShowHScrollBar  = true;
            Zed.IsAutoScrollRange = true;

            thePane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 210, 255), -45F);
            // Disable the Titles
            thePane.Title.IsVisible      = false;
            thePane.Legend.FontSpec.Size = 8;

            thePane.XAxis.Type                = AxisType.Date;
            thePane.XAxis.Title.IsVisible     = false;
            thePane.XAxis.Scale.Min           = Orbits.Start.UtcDateTime.ToOADate();
            thePane.XAxis.Scale.Max           = Orbits.End.UtcDateTime.ToOADate();
            thePane.XAxis.Scale.FontSpec.Size = 8;
            thePane.XAxis.MajorGrid.IsVisible = true;
            thePane.XAxis.MajorGrid.Color     = Color.LightGray;

            thePane.XAxis.Scale.Format = "yyyy-MMdd";

            //thePane.XAxis.Scale.Format = History.ActivedDateFormat;
            thePane.XAxis.Scale.MinAuto = false;
            thePane.XAxis.Scale.MaxAuto = false;


            thePane.YAxis.Title.IsVisible = false;
            //thePane.YAxis.Title.Text = "Quadranted Degrees";
            //thePane.YAxis.Title.FontSpec.FontColor = Color.Green;
            thePane.YAxis.Title.FontSpec.Size      = 8;
            thePane.YAxis.Scale.FontSpec.Size      = 8;
            thePane.YAxis.Scale.FontSpec.FontColor = Color.Green;
            thePane.YAxis.Scale.Align          = AlignP.Inside;
            thePane.YAxis.MajorTic.IsOpposite  = false;
            thePane.YAxis.MinorTic.IsOpposite  = false;
            thePane.YAxis.Scale.MagAuto        = false;
            thePane.YAxis.MajorGrid.IsVisible  = true;
            thePane.YAxis.MajorGrid.Color      = Color.LightGray;
            thePane.YAxis.MajorGrid.IsZeroLine = false;
            thePane.YAxis.Scale.MinAuto        = false;
            thePane.YAxis.Scale.MaxAuto        = false;
            thePane.YAxis.Scale.FormatAuto     = true;
            ResetYScale();

            thePane.Y2Axis.IsVisible                = false;
            thePane.Y2Axis.MajorGrid.IsZeroLine     = false;
            thePane.Y2Axis.Title.Text               = "Latitude";
            thePane.Y2Axis.Title.FontSpec.Size      = 8;
            thePane.Y2Axis.Title.FontSpec.FontColor = Color.DarkGray;
            thePane.Y2Axis.Scale.FontSpec.Size      = 8;
            thePane.Y2Axis.Scale.FontSpec.FontColor = Color.DarkGray;
            thePane.Y2Axis.MajorTic.IsOpposite      = false;
            thePane.Y2Axis.MinorTic.IsOpposite      = false;
            thePane.Y2Axis.Scale.Align              = AlignP.Inside;
            thePane.Y2Axis.MajorGrid.IsZeroLine     = true;
            thePane.Y2Axis.Scale.MinAuto            = false;
            thePane.Y2Axis.Scale.MaxAuto            = false;
            thePane.Y2Axis.Scale.FormatAuto         = true;
            thePane.Y2Axis.Scale.Max                = 0.00001;
            thePane.Y2Axis.Scale.Min                = -0.00001;
            thePane.Y2Axis.Scale.MajorStepAuto      = false;
            thePane.Y2Axis.Scale.MinorStepAuto      = false;
            thePane.Y2Axis.Scale.FormatAuto         = true;
            thePane.Y2Axis.Scale.MagAuto            = false;

            Y2Axis yAxis3 = new Y2Axis("Speed/Distance");

            yAxis3.IsVisible = false;
            thePane.Y2AxisList.Add(yAxis3);
            yAxis3.MajorGrid.IsZeroLine     = false;
            yAxis3.Title.FontSpec.Size      = 8;
            yAxis3.Title.FontSpec.FontColor = Color.DarkCyan;
            yAxis3.Scale.FontSpec.Size      = 8;
            yAxis3.Scale.FontSpec.FontColor = Color.DarkCyan;
            yAxis3.MajorTic.IsOpposite      = false;
            yAxis3.MinorTic.IsOpposite      = false;
            yAxis3.Scale.Align          = AlignP.Inside;
            yAxis3.MajorGrid.IsZeroLine = true;
            yAxis3.Scale.MinAuto        = false;
            yAxis3.Scale.MaxAuto        = false;
            yAxis3.Scale.FormatAuto     = true;
            yAxis3.Scale.Max            = 0.00001;
            yAxis3.Scale.Min            = -0.00001;
            //yAxis3.Scale.MajorStep = 2;
            yAxis3.Scale.MajorStepAuto = false;
            yAxis3.Scale.MinorStepAuto = false;
            yAxis3.Scale.MagAuto       = true;

            thePane.AxisChange();
        }
Exemplo n.º 17
0
        /// <summary>
        /// 绘制矩形图,根据BarChartType和ds数量确定Bar绘制方式。
        /// 当BarChartType为Vertical或Horizontal,且ds数量大于1时,为多组柱图;其余情况为单柱图
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="g"></param>
        /// <param name="cs"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        internal static void AddBars(DataCollectionBar dc, Graphics g, ChartStyle cs, XAxis xa, YAxis ya, Y2Axis y2a)
        {
            int numberOfDataSeries = dc.DataSeriesList.Count;
            //比较各列个数,柱状图需统一个数,以最多个数为准
            int  nPoints      = 0;
            bool isConsistant = true;
            bool isY2         = false;

            foreach (DataSeries ds in dc.DataSeriesList)
            {
                if (nPoints < ds.PointList.Count)
                {
                    nPoints = ds.PointList.Count;
                }
                if (ds.IsY2Data)
                {
                    isY2 = true;
                }
            }

            // Draw bars:
            ArrayList temp = new ArrayList();

            float[] tempy  = new float[nPoints];
            PointF  temppt = new PointF();
            int     n      = 0;

            foreach (DataSeries ds in dc.DataSeriesList)
            {
                Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.LineThickness);
                aPen.DashStyle = ds.LineStyle.LinePattern;
                SolidBrush aBrush;
                if (ds.FillColor != Color.Empty)
                {
                    aBrush = new SolidBrush(ds.FillColor);
                }
                else
                {
                    aBrush = new SolidBrush(Color.FromArgb(180, ds.LineStyle.LineColor));
                }
                PointF[] pts = new PointF[4];
                PointF   pt;
                float    width;
                if (dc.BarChartType == BarChartTypeEnum.Vertical)
                {
                    if (numberOfDataSeries == 1)
                    {
                        width = (float)xa.XTick * dc.BarWidth;
                        if (!isY2)
                        {
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                pt = (PointF)ds.PointList[i];
                                float x = pt.X - xa.XTick / 2;
                                pts[0] = cs.Point2D(new PointF(x - width / 2, 0), xa, ya);
                                pts[1] = cs.Point2D(new PointF(x + width / 2, 0), xa, ya);
                                pts[2] = cs.Point2D(new PointF(x + width / 2, pt.Y), xa, ya);
                                pts[3] = cs.Point2D(new PointF(x - width / 2, pt.Y), xa, ya);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                pt = (PointF)ds.PointList[i];
                                float x = pt.X - xa.XTick / 2;
                                pts[0] = cs.Point2DY2(new PointF(x - width / 2, 0), xa, y2a);
                                pts[1] = cs.Point2DY2(new PointF(x + width / 2, 0), xa, y2a);
                                pts[2] = cs.Point2DY2(new PointF(x + width / 2, pt.Y), xa, y2a);
                                pts[3] = cs.Point2DY2(new PointF(x - width / 2, pt.Y), xa, y2a);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                    }
                    else if (numberOfDataSeries > 1)
                    {
                        //width = 0.7f * (float)xa.XTick;
                        dc.BarWidth = (dc.BarWidth > 0 && dc.BarWidth <= 1) ? dc.BarWidth : 0.95f;
                        width       = (float)xa.XTick * dc.BarWidth;

                        if (!isY2)
                        {
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                pt = (PointF)ds.PointList[i];
                                float x     = pt.X;// - (float)xa.XTick / 2
                                float w1    = width / numberOfDataSeries;
                                float w     = dc.BarWidth * w1;
                                float space = (w1 - w) / 2;
                                pts[0] = cs.Point2D(new PointF(x - width / 2 + space + n * w1, 0), xa, ya);
                                pts[1] = cs.Point2D(new PointF(x - width / 2 + space + n * w1 + w, 0), xa, ya);
                                pts[2] = cs.Point2D(new PointF(x - width / 2 + space + n * w1 + w, pt.Y), xa, ya);
                                pts[3] = cs.Point2D(new PointF(x - width / 2 + space + n * w1, pt.Y), xa, ya);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                pt = (PointF)ds.PointList[i];
                                float x     = pt.X - (float)xa.XTick / 2;
                                float w1    = width / numberOfDataSeries;
                                float w     = dc.BarWidth * w1;
                                float space = (w1 - w) / 2;
                                pts[0] = cs.Point2DY2(new PointF(x - width / 2 + space + n * w1, 0), xa, y2a);
                                pts[1] = cs.Point2DY2(new PointF(x - width / 2 + space + n * w1 + w, 0), xa, y2a);
                                pts[2] = cs.Point2DY2(new PointF(x - width / 2 + space + n * w1 + w, pt.Y), xa, y2a);
                                pts[3] = cs.Point2DY2(new PointF(x - width / 2 + space + n * w1, pt.Y), xa, y2a);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                    }
                }
                else if (dc.BarChartType == BarChartTypeEnum.VerticalOverlay && numberOfDataSeries > 1)
                {
                    width = (float)xa.XTick * dc.BarWidth;
                    width = width / (float)Math.Pow(2, n);

                    if (!isY2)
                    {
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            pt = (PointF)ds.PointList[i];
                            float x = pt.X - xa.XTick / 2;
                            pts[0] = cs.Point2D(new PointF(x - width / 2, 0), xa, ya);
                            pts[1] = cs.Point2D(new PointF(x + width / 2, 0), xa, ya);
                            pts[2] = cs.Point2D(new PointF(x + width / 2, pt.Y), xa, ya);
                            pts[3] = cs.Point2D(new PointF(x - width / 2, pt.Y), xa, ya);
                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            pt = (PointF)ds.PointList[i];
                            float x = pt.X - xa.XTick / 2;
                            pts[0] = cs.Point2DY2(new PointF(x - width / 2, 0), xa, y2a);
                            pts[1] = cs.Point2DY2(new PointF(x + width / 2, 0), xa, y2a);
                            pts[2] = cs.Point2DY2(new PointF(x + width / 2, pt.Y), xa, y2a);
                            pts[3] = cs.Point2DY2(new PointF(x - width / 2, pt.Y), xa, y2a);
                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                }
                else if (dc.BarChartType == BarChartTypeEnum.VerticalStack && numberOfDataSeries > 1)
                {
                    width = xa.XTick * dc.BarWidth;

                    if (!isY2)
                    {
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            pt = (PointF)ds.PointList[i];
                            if (temp.Count > 0)
                            {
                                tempy[i] = tempy[i] + ((PointF)temp[i]).Y;
                            }
                            float x = pt.X - xa.XTick / 2;
                            pts[0] = cs.Point2D(new PointF(x - width / 2, 0 + tempy[i]), xa, ya);
                            pts[1] = cs.Point2D(new PointF(x + width / 2, 0 + tempy[i]), xa, ya);
                            pts[2] = cs.Point2D(new PointF(x + width / 2, pt.Y + tempy[i]), xa, ya);
                            pts[3] = cs.Point2D(new PointF(x - width / 2, pt.Y + tempy[i]), xa, ya);

                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            pt = (PointF)ds.PointList[i];
                            if (temp.Count > 0)
                            {
                                tempy[i] = tempy[i] + ((PointF)temp[i]).Y;
                            }
                            float x = pt.X - xa.XTick / 2;
                            pts[0] = cs.Point2DY2(new PointF(x - width / 2, 0 + tempy[i]), xa, y2a);
                            pts[1] = cs.Point2DY2(new PointF(x + width / 2, 0 + tempy[i]), xa, y2a);
                            pts[2] = cs.Point2DY2(new PointF(x + width / 2, pt.Y + tempy[i]), xa, y2a);
                            pts[3] = cs.Point2DY2(new PointF(x - width / 2, pt.Y + tempy[i]), xa, y2a);

                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                    temp = ds.PointList;
                }

                else if (dc.BarChartType == BarChartTypeEnum.Horizontal)
                {
                    if (numberOfDataSeries == 1)
                    {
                        if (!isY2)
                        {
                            width = ya.YTick * dc.BarWidth;
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                temppt = (PointF)ds.PointList[i];
                                pt     = new PointF(temppt.Y, temppt.X);
                                float y = pt.Y - ya.YTick / 2;
                                pts[0] = cs.Point2D(new PointF(0, y - width / 2), xa, ya);
                                pts[1] = cs.Point2D(new PointF(0, y + width / 2), xa, ya);
                                pts[2] = cs.Point2D(new PointF(pt.X, y + width / 2), xa, ya);
                                pts[3] = cs.Point2D(new PointF(pt.X, y - width / 2), xa, ya);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                        else
                        {
                            width = y2a.Y2Tick * dc.BarWidth;
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                temppt = (PointF)ds.PointList[i];
                                pt     = new PointF(temppt.Y, temppt.X);
                                float y = pt.Y - y2a.Y2Tick / 2;
                                pts[0] = cs.Point2DY2(new PointF(0, y - width / 2), xa, y2a);
                                pts[1] = cs.Point2DY2(new PointF(0, y + width / 2), xa, y2a);
                                pts[2] = cs.Point2DY2(new PointF(pt.X, y + width / 2), xa, y2a);
                                pts[3] = cs.Point2DY2(new PointF(pt.X, y - width / 2), xa, y2a);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                    }
                    else if (numberOfDataSeries > 1)
                    {
                        //width = 0.7f * ya.YTick;
                        dc.BarWidth = (dc.BarWidth > 0 && dc.BarWidth <= 1) ? dc.BarWidth : 0.95f;

                        if (!isY2)
                        {
                            width = (float)ya.YTick * dc.BarWidth;
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                temppt = (PointF)ds.PointList[i];
                                pt     = new PointF(temppt.Y, temppt.X);
                                float w1    = width / numberOfDataSeries;
                                float w     = dc.BarWidth * w1;
                                float space = (w1 - w) / 2;
                                float y     = pt.Y - ya.YTick / 2;
                                pts[0] = cs.Point2D(new PointF(0,
                                                               y - width / 2 + space + n * w1), xa, ya);
                                pts[1] = cs.Point2D(new PointF(0,
                                                               y - width / 2 + space + n * w1 + w), xa, ya);
                                pts[2] = cs.Point2D(new PointF(pt.X,
                                                               y - width / 2 + space + n * w1 + w), xa, ya);
                                pts[3] = cs.Point2D(new PointF(pt.X,
                                                               y - width / 2 + space + n * w1), xa, ya);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                        else
                        {
                            width = (float)y2a.Y2Tick * dc.BarWidth;
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                temppt = (PointF)ds.PointList[i];
                                pt     = new PointF(temppt.Y, temppt.X);
                                float w1    = width / numberOfDataSeries;
                                float w     = dc.BarWidth * w1;
                                float space = (w1 - w) / 2;
                                float y     = pt.Y - y2a.Y2Tick / 2;
                                pts[0] = cs.Point2DY2(new PointF(0,
                                                                 y - width / 2 + space + n * w1), xa, y2a);
                                pts[1] = cs.Point2DY2(new PointF(0,
                                                                 y - width / 2 + space + n * w1 + w), xa, y2a);
                                pts[2] = cs.Point2DY2(new PointF(pt.X,
                                                                 y - width / 2 + space + n * w1 + w), xa, y2a);
                                pts[3] = cs.Point2DY2(new PointF(pt.X,
                                                                 y - width / 2 + space + n * w1), xa, y2a);
                                g.FillPolygon(aBrush, pts);
                                if (ds.LineStyle.IsVisible)
                                {
                                    g.DrawPolygon(aPen, pts);
                                }
                            }
                        }
                    }
                }
                else if (dc.BarChartType == BarChartTypeEnum.HorizontalOverlay && numberOfDataSeries > 1)
                {
                    if (!isY2)
                    {
                        width = ya.YTick * dc.BarWidth;
                        width = width / (float)Math.Pow(2, n);
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            temppt = (PointF)ds.PointList[i];
                            pt     = new PointF(temppt.Y, temppt.X);
                            float y = pt.Y - ya.YTick / 2;
                            pts[0] = cs.Point2D(new PointF(0, y - width / 2), xa, ya);
                            pts[1] = cs.Point2D(new PointF(0, y + width / 2), xa, ya);
                            pts[2] = cs.Point2D(new PointF(pt.X, y + width / 2), xa, ya);
                            pts[3] = cs.Point2D(new PointF(pt.X, y - width / 2), xa, ya);
                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                    else
                    {
                        width = y2a.Y2Tick * dc.BarWidth;
                        width = width / (float)Math.Pow(2, n);
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            temppt = (PointF)ds.PointList[i];
                            pt     = new PointF(temppt.Y, temppt.X);
                            float y = pt.Y - y2a.Y2Tick / 2;
                            pts[0] = cs.Point2DY2(new PointF(0, y - width / 2), xa, y2a);
                            pts[1] = cs.Point2DY2(new PointF(0, y + width / 2), xa, y2a);
                            pts[2] = cs.Point2DY2(new PointF(pt.X, y + width / 2), xa, y2a);
                            pts[3] = cs.Point2DY2(new PointF(pt.X, y - width / 2), xa, y2a);
                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                }
                else if (dc.BarChartType == BarChartTypeEnum.HorizontalStack && numberOfDataSeries > 1)
                {
                    if (!isY2)
                    {
                        width = ya.YTick * dc.BarWidth;
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            temppt = (PointF)ds.PointList[i];
                            pt     = new PointF(temppt.Y, temppt.X);
                            if (temp.Count > 0)
                            {
                                temppt   = (PointF)temp[i];
                                tempy[i] = tempy[i] + temppt.Y;
                            }
                            float y = pt.Y - ya.YTick / 2;
                            pts[0] = cs.Point2D(new PointF(0 + tempy[i], y - width / 2), xa, ya);
                            pts[1] = cs.Point2D(new PointF(0 + tempy[i], y + width / 2), xa, ya);
                            pts[2] = cs.Point2D(new PointF(pt.X + tempy[i], y + width / 2), xa, ya);
                            pts[3] = cs.Point2D(new PointF(pt.X + tempy[i], y - width / 2), xa, ya);

                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                    else
                    {
                        width = y2a.Y2Tick * dc.BarWidth;
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            temppt = (PointF)ds.PointList[i];
                            pt     = new PointF(temppt.Y, temppt.X);
                            if (temp.Count > 0)
                            {
                                temppt   = (PointF)temp[i];
                                tempy[i] = tempy[i] + temppt.Y;
                            }
                            float y = pt.Y - y2a.Y2Tick / 2;
                            pts[0] = cs.Point2DY2(new PointF(0 + tempy[i], y - width / 2), xa, y2a);
                            pts[1] = cs.Point2DY2(new PointF(0 + tempy[i], y + width / 2), xa, y2a);
                            pts[2] = cs.Point2DY2(new PointF(pt.X + tempy[i], y + width / 2), xa, y2a);
                            pts[3] = cs.Point2DY2(new PointF(pt.X + tempy[i], y - width / 2), xa, y2a);

                            g.FillPolygon(aBrush, pts);
                            if (ds.LineStyle.IsVisible)
                            {
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                    }
                    temp = ds.PointList;
                }
                n++;
                aPen.Dispose();
                aBrush.Dispose();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 坐标轴检查,便于手动设定limit后不强制开启自适应
        /// </summary>
        /// <param name="dclist"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        /// <param name="y2a"></param>
        /// <returns></returns>
        internal static bool AxesFitCheck(List <DataCollection> dclist, XAxis xa, YAxis ya, Y2Axis y2a, RAxis ra)
        {
            bool openFit, xopenfit, yopenfit, y2openfit, ropenfit;

            openFit = xopenfit = yopenfit = y2openfit = ropenfit = false;
            float xmax, xmin, ymax, ymin, y2max, y2min, rmin, rmax;

            xmax = xmin = ymax = ymin = y2max = y2min = rmin = rmax = -99;
            //含柱状图时,底轴两侧预留一个tick
            float barmin, barmax;

            barmin = barmax = -99;
            bool havebar = false;  bool baraxisX = true;

            try
            {
                foreach (DataCollection dc in dclist)
                {
                    #region AreaChart
                    if (dc.ChartType == Chart2DTypeEnum.AreaChart)
                    {
                        int  nPoints      = 0;
                        bool isConsistant = true;
                        bool isY2         = false;
                        foreach (DataSeries ds in dc.DataSeriesList)
                        {
                            if (nPoints == 0)
                            {
                                nPoints = ds.PointList.Count;
                            }
                            else if (nPoints != ds.PointList.Count)
                            {
                                isConsistant = false;
                                return(openFit);
                            }
                            if (ds.IsY2Data)
                            {
                                isY2 = true;
                            }
                        }
                        try
                        {
                            DataSeries ds1 = (DataSeries)dc.DataSeriesList[0];
                            if (xmax == -99 && xmin == -99)
                            {
                                xmax = xmin = ((PointF)ds1.PointList[0]).X;
                            }
                            if (!isY2 && ymax == -99 && ymin == -99)
                            {
                                ymax = ymin = ((PointF)ds1.PointList[0]).Y;
                            }
                            else if (isY2 && y2max == -99 && y2min == -99)
                            {
                                y2max = y2min = ((PointF)ds1.PointList[0]).Y;
                            }
                        }
                        catch
                        {
                            if (xmax == -99 && xmin == -99)
                            {
                                xmax = xmin = 0;
                            }
                            if (ymax == ymin && ymax == -99)
                            {
                                ymax = ymin = 0;
                            }
                            if (y2max == y2min && y2max == -99)
                            {
                                y2max = y2min = 0;
                            }
                        }

                        if (((DataCollectionArea)dc).AreaChartType == AreaCharts.AreaChartTypeEnum.Area)
                        {
                            float[] ySum = new float[nPoints];
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                for (int i = 0; i < nPoints; i++)
                                {
                                    PointF p = (PointF)ds.PointList[i];
                                    xmax = (p.X > xmax) ? p.X : xmax;
                                    xmin = (p.X < xmin) ? p.X : xmin;

                                    if (!ds.IsY2Data)
                                    {
                                        ymax = (p.Y > ymax) ? p.Y : ymax;
                                        ymin = (p.Y < ymin) ? p.Y : ymin;
                                    }
                                    else
                                    {
                                        y2max = (p.Y > y2max) ? p.Y : y2max;
                                        y2min = (p.Y < y2min) ? p.Y : y2min;
                                    }
                                    ySum[i] += p.Y;
                                }
                            }
                            if (!isY2)
                            {
                                foreach (float y in ySum)
                                {
                                    ymax = (y > ymax) ? y : ymax;
                                    ymin = (y < ymin) ? y : ymin;
                                }
                            }
                            else
                            {
                                foreach (float y in ySum)
                                {
                                    y2max = (y > y2max) ? y : y2max;
                                    y2min = (y < y2min) ? y : y2min;
                                }
                            }
                        }
                        else if (((DataCollectionArea)dc).AreaChartType == AreaCharts.AreaChartTypeEnum.PercentArea)
                        {
                            //纵轴表示百分比
                            float ytick = 0.2f;
                            if (!isY2)
                            {
                                ya.YLimMax = ymax = 1;
                                ya.YLimMin = ymin = 0;
                                ya.YTick   = ytick;
                            }
                            else
                            {
                                y2a.Y2LimMax = ymax = 1;
                                y2a.Y2LimMin = ymin = 0;
                                y2a.Y2Tick   = ytick;
                            }
                        }
                    }
                    #endregion

                    #region BarChart
                    else if (dc.ChartType == Chart2DTypeEnum.BarChart)
                    {
                        havebar = true;
                        int  nPoints = 0;
                        bool isY2    = false;
                        foreach (DataSeries ds in dc.DataSeriesList)
                        {
                            if (nPoints < ds.PointList.Count)
                            {
                                nPoints = ds.PointList.Count;
                            }
                            if (ds.IsY2Data)
                            {
                                isY2 = true;
                            }
                        }
                        try
                        {
                            DataSeries ds1 = (DataSeries)dc.DataSeriesList[0];
                            if (xmax == -99 && xmin == -99)
                            {
                                xmax = xmin = ((PointF)ds1.PointList[0]).X;
                            }
                            if (!isY2 && ymax == -99 && ymin == -99)
                            {
                                ymax = ymin = ((PointF)ds1.PointList[0]).Y;
                            }
                            else if (isY2 && y2max == -99 && y2min == -99)
                            {
                                y2max = y2min = ((PointF)ds1.PointList[0]).Y;
                            }

                            if (((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.Vertical || ((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.VerticalOverlay || ((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.VerticalStack)
                            {
                                barmax = barmin = ((PointF)ds1.PointList[0]).X;
                            }
                            else
                            {
                                barmax   = barmin = ((PointF)ds1.PointList[0]).Y;
                                baraxisX = false;
                            }
                        }
                        catch
                        {
                            if (xmax == -99 && xmin == -99)
                            {
                                xmax = xmin = 0;
                            }
                            if (ymax == ymin && ymax == -99)
                            {
                                ymax = ymin = 0;
                            }
                            if (y2max == y2min && y2max == -99)
                            {
                                y2max = y2min = 0;
                            }
                            barmax = barmin = 0;
                        }
                        //不同方向Bar影响不同轴的自适应情况
                        if (((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.Vertical || ((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.VerticalOverlay)
                        {
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                foreach (PointF p in ds.PointList)
                                {
                                    xmax   = (p.X > xmax) ? p.X : xmax;
                                    xmin   = (p.X < xmin) ? p.X : xmin;
                                    barmax = (p.X > barmax) ? p.X : barmax;
                                    barmin = (p.X < barmin) ? p.X : barmin;

                                    if (!ds.IsY2Data)
                                    {
                                        ymax = (p.Y > ymax) ? p.Y : ymax;
                                        ymin = (p.Y < ymin) ? p.Y : ymin;
                                    }
                                    else
                                    {
                                        y2max = (p.Y > y2max) ? p.Y : y2max;
                                        y2min = (p.Y < y2min) ? p.Y : y2min;
                                    }
                                }
                            }
                        }
                        else if (((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.VerticalStack)
                        {
                            float[] ySum = new float[nPoints];
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                for (int i = 0; i < nPoints; i++)
                                {
                                    PointF p = (PointF)ds.PointList[i];
                                    xmax = (p.X > xmax) ? p.X : xmax;
                                    xmin = (p.X < xmin) ? p.X : xmin;

                                    barmax = (p.X > barmax) ? p.X : barmax;
                                    barmin = (p.X < barmin) ? p.X : barmin;

                                    if (!ds.IsY2Data)
                                    {
                                        ymax = (p.Y > ymax) ? p.Y : ymax;
                                        ymin = (p.Y < ymin) ? p.Y : ymin;
                                    }
                                    else
                                    {
                                        y2max = (p.Y > y2max) ? p.Y : y2max;
                                        y2min = (p.Y < y2min) ? p.Y : y2min;
                                    }
                                    ySum[i] += p.Y;
                                }
                            }
                            if (!isY2)
                            {
                                foreach (float y in ySum)
                                {
                                    ymax = (y > ymax) ? y : ymax;
                                    ymin = (y < ymin) ? y : ymin;
                                }
                            }
                            else
                            {
                                foreach (float y in ySum)
                                {
                                    y2max = (y > y2max) ? y : y2max;
                                    y2min = (y < y2min) ? y : y2min;
                                }
                            }
                        }
                        else if (((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.Horizontal || ((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.HorizontalOverlay)
                        {
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                foreach (PointF p in ds.PointList)
                                {
                                    xmax = (p.Y > xmax) ? p.Y : xmax;
                                    xmin = (p.Y < xmin) ? p.Y : xmin;
                                    ymax = (p.X > ymax) ? p.X : ymax;
                                    ymin = (p.X < ymin) ? p.X : ymin;

                                    barmax = (p.Y > barmax) ? p.Y : barmax;
                                    barmin = (p.Y < barmin) ? p.Y : barmin;
                                }
                            }
                        }
                        else if (((DataCollectionBar)dc).BarChartType == BarCharts.BarChartTypeEnum.HorizontalStack)
                        {
                            float[] xSum = new float[nPoints];
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                for (int i = 0; i < nPoints; i++)
                                {
                                    PointF p = (PointF)ds.PointList[i];
                                    xmax     = (p.Y > xmax) ? p.Y : xmax;
                                    xmin     = (p.Y < xmin) ? p.Y : xmin;
                                    xSum[i] += p.Y;
                                    ymax     = (p.X > ymax) ? p.X : ymax;
                                    ymin     = (p.X < ymin) ? p.X : ymin;

                                    barmax = (p.Y > barmax) ? p.Y : barmax;
                                    barmin = (p.Y < barmin) ? p.Y : barmin;
                                }
                            }
                            foreach (float x in xSum)
                            {
                                xmax = (x > xmax) ? x : xmax;
                                xmin = (x < xmin) ? x : xmin;
                            }
                        }
                    }
                    #endregion

                    #region LineChart
                    else if (dc.ChartType == Chart2DTypeEnum.LineChart)
                    {
                        try
                        {
                            DataSeries ds1 = (DataSeries)dc.DataSeriesList[0];
                            if (xmax == -99 && xmin == -99)
                            {
                                xmax = xmin = ((PointF)ds1.PointList[0]).X;
                            }
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                if (ds.LineChartType == LineCharts.LineChartTypeEnum.Candle || ds.LineChartType == LineCharts.LineChartTypeEnum.HiLoOpenClose || ds.LineChartType == LineCharts.LineChartTypeEnum.HiLo)
                                {
                                    if (!ds.IsY2Data && ymax == ymin && ymax == -99)
                                    {
                                        ymax = ymin = Convert.ToSingle(ds.DataString[2, 0]);
                                    }
                                    else if (ds.IsY2Data && y2max == y2min && y2max == -99)
                                    {
                                        y2max = y2min = Convert.ToSingle(ds.DataString[2, 0]);
                                    }
                                }
                                else
                                {
                                    if (!ds.IsY2Data && ymax == ymin && ymax == -99)
                                    {
                                        ymax = ymin = ((PointF)ds.PointList[0]).Y;
                                    }
                                    else if (ds.IsY2Data && y2max == y2min && y2max == -99)
                                    {
                                        y2max = y2min = ((PointF)ds.PointList[0]).Y;
                                    }
                                }
                            }
                        }
                        catch
                        {
                            if (xmax == -99 && xmin == -99)
                            {
                                xmax = xmin = 0;
                            }
                            if (ymax == ymin && ymax == -99)
                            {
                                ymax = ymin = 0;
                            }
                            if (y2max == y2min && y2max == -99)
                            {
                                y2max = y2min = 0;
                            }
                        }
                        foreach (DataSeries ds in dc.DataSeriesList)
                        {
                            #region 附加型
                            if (ds.ErrorList.Count != 0 && ds.LineChartType == LineCharts.LineChartTypeEnum.ErrorBar)
                            {
                                for (int i = 0; i < ds.ErrorList.Count; i++)
                                {
                                    PointF p    = (PointF)ds.PointList[i];
                                    PointF errp = (PointF)ds.ErrorList[i];
                                    xmax = (p.X > xmax) ? p.X : xmax;
                                    xmin = (p.X < xmin) ? p.X : xmin;
                                    if (!ds.IsY2Data)
                                    {
                                        ymax = (p.Y + errp.Y > ymax) ? p.Y + errp.Y : ymax;
                                        ymin = (p.Y - errp.Y < ymin) ? p.Y - errp.Y : ymin;
                                    }
                                    else
                                    {
                                        y2max = (p.Y + errp.Y > y2max) ? p.Y + errp.Y : y2max;
                                        y2min = (p.Y - errp.Y < y2min) ? p.Y - errp.Y : y2min;
                                    }
                                }
                            }
                            else if (ds.DataString != null && (ds.LineChartType == LineCharts.LineChartTypeEnum.Candle || ds.LineChartType == LineCharts.LineChartTypeEnum.HiLoOpenClose || ds.LineChartType == LineCharts.LineChartTypeEnum.HiLo))
                            {
                                xmax = (ds.DataString.GetLength(1) > xmax) ? ds.DataString.GetLength(1) : xmax;
                                xmin = (0 < xmin) ? 0 : xmin;
                                for (int i = 0; i < ds.DataString.GetLength(1); i++)
                                {
                                    float ptHigh = Convert.ToSingle(ds.DataString[2, i]);
                                    float ptLow  = Convert.ToSingle(ds.DataString[3, i]);
                                    if (!ds.IsY2Data)
                                    {
                                        ymax = (ptHigh > ymax) ? ptHigh : ymax;
                                        ymin = (ptLow < ymin) ? ptLow : ymin;
                                    }
                                    else
                                    {
                                        y2max = (ptHigh > y2max) ? ptHigh : y2max;
                                        y2min = (ptLow < y2min) ? ptLow : y2min;
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                foreach (PointF p in ds.PointList)
                                {
                                    xmax = (p.X > xmax) ? p.X : xmax;
                                    xmin = (p.X < xmin) ? p.X : xmin;
                                    if (!ds.IsY2Data)
                                    {
                                        ymax = (p.Y > ymax) ? p.Y : ymax;
                                        ymin = (p.Y < ymin) ? p.Y : ymin;
                                    }
                                    else
                                    {
                                        y2max = (p.Y > y2max) ? p.Y : y2max;
                                        y2min = (p.Y < y2min) ? p.Y : y2min;
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region PolarChart
                    else if (dc.ChartType == Chart2DTypeEnum.PolorChart)
                    {
                        try
                        {
                            DataSeries ds1 = (DataSeries)dc.DataSeriesList[0];
                            if (rmin == -99 && rmin == -99)
                            {
                                rmax = rmin = ((PointF)ds1.PointList[0]).Y;
                            }
                        }
                        catch
                        {
                            if (rmax == -99 && rmin == -99)
                            {
                                rmax = rmin = 0;
                            }
                        }

                        if (((DataCollectionPolar)dc).PolarChartType == PolarCharts.PolarChartTypeEnum.Rose)
                        {
                            rmin = 0;
                            Dictionary <float, float> rSum = new Dictionary <float, float>();
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                foreach (PointF p in ds.PointList)
                                {
                                    if (rSum.ContainsKey(p.X))
                                    {
                                        rSum[p.X] += p.Y;
                                    }
                                    else
                                    {
                                        rSum.Add(p.X, p.Y);
                                    }
                                }
                            }
                            foreach (float r in rSum.Values)
                            {
                                rmax = (r > rmax) ? r : rmax;
                                rmin = (r < rmin) ? r : rmin;
                            }
                        }
                        else
                        {
                            foreach (DataSeries ds in dc.DataSeriesList)
                            {
                                foreach (PointF p in ds.PointList)
                                {
                                    rmax = (p.Y > rmax) ? p.Y : rmax;
                                    rmin = (p.Y < rmin) ? p.Y : rmin;
                                }
                            }
                        }
                    }
                    #endregion
                }
                //自适应触发条件:极值不满足或范围过大
                if (xa.XLimMax < xmax || xa.XLimMin > xmin || (xa.XLimMax - xa.XLimMin) / 2 > (xmax - xmin) || xa.XTick > (xa.XLimMax - xa.XLimMin))
                {
                    xopenfit = true;
                    float xtick = 0;
                    FitModify(ref xmax, ref xmin, out xtick);
                    xa.XLimMax = xmax;
                    xa.XLimMin = xmin;
                    xa.XTick   = xtick;
                }
                if (ya.YLimMax < ymax || ya.YLimMin > ymin || (ya.YLimMax - ya.YLimMin) / 2 > (ymax - ymin) || ya.YTick > (ya.YLimMax - ya.YLimMin))
                {
                    yopenfit = true;
                    float ytick = 0;
                    FitModify(ref ymax, ref ymin, out ytick);
                    ya.YLimMax = ymax;
                    ya.YLimMin = ymin;
                    ya.YTick   = ytick;
                }
                if (y2a.Y2LimMax < y2max || y2a.Y2LimMin > y2min || (y2a.Y2LimMax - y2a.Y2LimMin) / 2 > (y2max - y2min) || y2a.Y2Tick > (y2a.Y2LimMax - y2a.Y2LimMin))
                {
                    y2openfit = true;
                    float y2tick = 0;
                    FitModify(ref y2max, ref y2min, out y2tick);
                    y2a.Y2LimMax = y2max;
                    y2a.Y2LimMin = y2min;
                    y2a.Y2Tick   = y2tick;
                }
                if (ra.RMax < rmax || ra.RMin > rmin || (ra.RMax - ra.RMin) / 2 > (rmax - rmin) || ra.RTick > (ra.RMax - ra.RMin))
                {
                    ropenfit = true;
                    float rtick = 0;
                    FitModify(ref rmax, ref rmin, out rtick);
                    ra.RMax  = rmax;
                    ra.RMin  = rmin;
                    ra.RTick = rtick;
                }

                //Bar的一侧宽度问题,预留一个tick
                if (havebar)
                {
                    if (baraxisX)
                    {
                        if (xa.XLimMin <= barmin && xa.XLimMin + xa.XTick > barmin)
                        {
                            xopenfit    = true;
                            xa.XLimMin -= xa.XTick;
                            if (xa.XMarkStartindex == 0)
                            {
                                xa.XTickMarkFull[0] = string.Empty;
                            }
                        }
                        if (xmin <= barmin && xmin + xa.XTick > barmin)
                        {
                            xa.XTickMarkFull[0] = string.Empty;
                        }
                        if (xa.XLimMax >= barmax && xa.XLimMax - xa.XTick < barmax)
                        {
                            xopenfit    = true;
                            xa.XLimMax += xa.XTick;
                        }
                    }
                    else
                    {
                        if (ya.YLimMin <= barmin && ya.YLimMin + ya.YTick > barmin)
                        {
                            yopenfit    = true;
                            ya.YLimMin -= ya.YTick;
                        }
                        if (ya.YLimMax >= barmax && ya.YLimMax - ya.YTick < barmax)
                        {
                            yopenfit    = true;
                            ya.YLimMax += ya.YTick;
                        }
                    }
                }
            }
            catch { }
            if (xopenfit || yopenfit || y2openfit || ropenfit)
            {
                openFit = true;
            }
            return(openFit);
        }
Exemplo n.º 19
0
        private void CreateGraph()
        {
            GraphPane myPane = zedGraphControl1.GraphPane;

            myPane.CurveList.Clear();
            myPane.Title.Text       = "Cycling Data";
            myPane.XAxis.Title.Text = "Time (Seconds)";
            myPane.YAxis.Title.Text = "HR";
            myPane.YAxis.Color      = Color.Blue;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Blue;
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.Text = "Speed";
            myPane.Y2Axis.Color      = Color.Yellow;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Yellow;
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Yellow;
            myPane.Y2Axis.IsVisible = true;

            YAxis YAxis1 = new YAxis("RPM");

            YAxis1.Title.FontSpec.FontColor = Color.Red;
            YAxis1.Scale.FontSpec.FontColor = Color.Red;
            YAxis1.Color = Color.Red;
            myPane.YAxisList.Add(YAxis1);
            YAxis YAxis2 = new YAxis("Altitude");

            YAxis2.Title.FontSpec.FontColor = Color.ForestGreen;
            YAxis2.Scale.FontSpec.FontColor = Color.ForestGreen;
            YAxis2.Color               = Color.ForestGreen;
            YAxis2.MajorTic.IsInside   = false;
            YAxis2.MinorTic.IsInside   = false;
            YAxis2.MajorTic.IsOpposite = false;
            YAxis2.MinorTic.IsOpposite = false;
            // Align the Y2 axis labels so they are flush to the axis
            YAxis2.Scale.Align = AlignP.Inside;
            myPane.YAxisList.Add(YAxis2);
            Y2Axis Y2Axis1 = new Y2Axis("Power");

            Y2Axis1.Title.FontSpec.FontColor = Color.HotPink;
            Y2Axis1.Scale.FontSpec.FontColor = Color.HotPink;
            Y2Axis1.Color = Color.HotPink;
            myPane.Y2AxisList.Add(Y2Axis1);
            Y2Axis1.IsVisible = true;

            //Creates data arrays based on the Sine function
            double        x, y1, y2, y3, y4, y5;
            PointPairList hrList       = new PointPairList();
            PointPairList speedList    = new PointPairList();
            PointPairList rpmList      = new PointPairList();
            PointPairList altitudeList = new PointPairList();
            PointPairList powerList    = new PointPairList();

            //HR,Speed,RPM,Altitude,Power
            for (int i = 0; i < dataGridView1.Rows.Count; i = i + 30)
            {
                x  = i;
                y1 = Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value);
                y2 = Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value);
                y3 = Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value);
                y4 = Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value);
                y5 = Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value);

                hrList.Add(x, y1);
                speedList.Add(x, y2);
                rpmList.Add(x, y3);
                altitudeList.Add(x, y4);
                powerList.Add(x, y5);
            }

            //Add heart rate
            LineItem curve;

            curve             = myPane.AddCurve("Heart Rate", hrList, Color.Blue);
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 1;
            curve.Line.Width  = 4.0F;

            //Add Speed
            LineItem curve1;

            curve1             = myPane.AddCurve("Speed", speedList, Color.Yellow);
            curve1.IsY2Axis    = true;
            curve1.Symbol.Fill = new Fill(Color.White);
            curve1.Symbol.Size = 1;
            curve1.Line.Width  = 4.0F;


            //Add RPM
            LineItem curve2;

            curve2             = myPane.AddCurve("RPM", rpmList, Color.Red);
            curve2.YAxisIndex  = 1;
            curve2.Symbol.Fill = new Fill(Color.White);
            curve2.Symbol.Size = 1;
            curve2.Line.Width  = 4.0F;



            //Add Altitude
            LineItem curve3;

            curve3             = myPane.AddCurve("Altitude", altitudeList, Color.ForestGreen);
            curve3.YAxisIndex  = 2;
            curve3.Symbol.Fill = new Fill(Color.White);
            curve3.Symbol.Size = 1;
            curve3.Line.Width  = 4.0F;

            //Add Power
            LineItem curve4;

            curve4             = myPane.AddCurve("Power", powerList, Color.HotPink);
            curve4.IsY2Axis    = true;
            curve4.YAxisIndex  = 4;
            curve4.Symbol.Fill = new Fill(Color.White);
            curve4.Symbol.Size = 1;
            curve4.Line.Width  = 4.0F;
            zedGraphControl1.AxisChange();
            SetSize();
        }
Exemplo n.º 20
0
        /// <summary>
        /// 绘制刻度线和标记(受数据影响)
        /// </summary>
        /// <param name="g"></param>
        /// <param name="lb"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        /// <param name="y2a"></param>
        private void AddTicks(Graphics g, XYLabel lb, XAxis xa, YAxis ya, Y2Axis y2a)
        {
            float fX, fY;
            //绘制x轴刻度线和标记:
            SolidBrush aBrush = new SolidBrush(xa.XTickStyle.TextColor);
            SizeF      sizeXTick;

            //出现在SetPlotArea和AddTicks中轴循环
            //for(float xTick = xa.XLimMin; xTick <= xa.XLimMax; xTick += xa.XTick)
            //弃用原因1:防止Tick为0时出现死循环
            //弃用原因2:float的精度损失程度累加

            int count = (int)Math.Round((xa.XLimMax - xa.XLimMin) / xa.XTick) + 1;

            for (int i = 0; i < count; i++)
            {
                fX = xa.XLimMin + i * xa.XTick;
                fX = DataDeal.FloatAccur(fX);
                PointF yAxisPoint = Point2D(new PointF(fX, ya.YLimMin), xa, ya);
                g.DrawLine(Pens.Black, yAxisPoint, new PointF(yAxisPoint.X, yAxisPoint.Y - 5f));

                StringFormat sFormat = new StringFormat();
                sFormat.Alignment = StringAlignment.Far;

                sizeXTick = g.MeasureString(xa.XTickMarkFull[i], xa.XTickStyle.TextFont);
                if (xa.XTickAngle != 0)
                {
                    g.TranslateTransform(yAxisPoint.X, yAxisPoint.Y); //设置旋转中心为文字中心
                    g.RotateTransform(xa.XTickAngle);                 //旋转
                    //g.TranslateTransform(-yAxisPoint.X, -yAxisPoint.Y);
                    g.DrawString(xa.XTickMarkFull[i], xa.XTickStyle.TextFont, aBrush, new PointF(0, 4f - sizeXTick.Height / 2), sFormat);
                    g.ResetTransform();
                }
                else
                {
                    g.DrawString(xa.XTickMarkFull[i], xa.XTickStyle.TextFont, aBrush, new PointF(yAxisPoint.X + sizeXTick.Width / 2, yAxisPoint.Y + 4f), sFormat);
                }
            }

            SizeF tickFontSize = g.MeasureString("A", ya.YTickStyle.TextFont);
            //绘制y轴刻度线和标记:
            int ycount = (int)Math.Round((ya.YLimMax - ya.YLimMin) / ya.YTick) + 1;

            for (int i = 0; i < ycount; i++)
            {
                fY = ya.YLimMin + i * ya.YTick;
                fY = DataDeal.FloatAccur(fY);
                PointF xAxisPoint = Point2D(new PointF(xa.XLimMin, fY), xa, ya);
                g.DrawLine(Pens.Black, xAxisPoint, new PointF(xAxisPoint.X + 5f, xAxisPoint.Y));

                StringFormat sFormat = new StringFormat();
                sFormat.Alignment = StringAlignment.Far;

                g.DrawString(fY.ToString(), ya.YTickStyle.TextFont, aBrush, new PointF(xAxisPoint.X - 3f, xAxisPoint.Y - tickFontSize.Height / 2), sFormat);
            }

            //绘制y2轴刻度线和标记:
            if (y2a.IsY2Axis)
            {
                int y2count = (int)Math.Round((y2a.Y2LimMax - y2a.Y2LimMin) / y2a.Y2Tick) + 1;
                for (int i = 0; i < y2count; i++)
                {
                    fY = y2a.Y2LimMin + i * y2a.Y2Tick;
                    fY = DataDeal.FloatAccur(fY);
                    PointF x2AxisPoint = Point2DY2(new PointF(xa.XLimMax, fY), xa, y2a);
                    g.DrawLine(Pens.Black, x2AxisPoint, new PointF(x2AxisPoint.X - 5f, x2AxisPoint.Y));

                    StringFormat sFormat = new StringFormat();
                    sFormat.Alignment = StringAlignment.Near;
                    g.DrawString(fY.ToString(), y2a.Y2TickStyle.TextFont, aBrush, new PointF(x2AxisPoint.X + 3f, x2AxisPoint.Y - tickFontSize.Height / 2), sFormat);
                }
            }
            aBrush.Dispose();
        }
Exemplo n.º 21
0
        public MultiYDemo() : base("A line graph with four Y axes",
                                   "Multi Y Demo", DemoType.Line)
        {
            GraphPane myPane = base.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text        = "Demonstration of Multi Y Graph";
            myPane.XAxis.Title.Text  = "Time, s";
            myPane.YAxis.Title.Text  = "Velocity, m/s";
            myPane.Y2Axis.Title.Text = "Acceleration, m/s2";

            // Make up some data points based on the Sine function
            PointPairList vList = new PointPairList();
            PointPairList aList = new PointPairList();
            PointPairList dList = new PointPairList();
            PointPairList eList = new PointPairList();

            // Fabricate some data values
            for (int i = 0; i < 30; i++)
            {
                double time         = (double)i;
                double acceleration = 2.0;
                double velocity     = acceleration * time;
                double distance     = acceleration * time * time / 2.0;
                double energy       = 100.0 * velocity * velocity / 2.0;
                aList.Add(time, acceleration);
                vList.Add(time, velocity);
                eList.Add(time, energy);
                dList.Add(time, distance);
            }

            // Generate a red curve with diamond symbols, and "Velocity" in the legend
            LineItem myCurve = myPane.AddCurve("Velocity",
                                               vList, Color.Red, SymbolType.Diamond);

            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Generate a blue curve with circle symbols, and "Acceleration" in the legend
            myCurve = myPane.AddCurve("Acceleration",
                                      aList, Color.Blue, SymbolType.Circle);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;

            // Generate a green curve with square symbols, and "Distance" in the legend
            myCurve = myPane.AddCurve("Distance",
                                      dList, Color.Green, SymbolType.Square);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 1;

            // Generate a Black curve with triangle symbols, and "Energy" in the legend
            myCurve = myPane.AddCurve("Energy",
                                      eList, Color.Black, SymbolType.Triangle);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;
            // Associate this curve with the second Y2 axis
            myCurve.YAxisIndex = 1;

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max   = 100;

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            myPane.Y2Axis.Scale.Min   = 1.5;
            myPane.Y2Axis.Scale.Max   = 3;

            // Create a second Y Axis, green
            YAxis yAxis3 = new YAxis("Distance, m");

            myPane.YAxisList.Add(yAxis3);
            yAxis3.Scale.FontSpec.FontColor = Color.Green;
            yAxis3.Title.FontSpec.FontColor = Color.Green;
            yAxis3.Color = Color.Green;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis3.MajorTic.IsInside   = false;
            yAxis3.MinorTic.IsInside   = false;
            yAxis3.MajorTic.IsOpposite = false;
            yAxis3.MinorTic.IsOpposite = false;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis3.Scale.Align = AlignP.Inside;

            Y2Axis yAxis4 = new Y2Axis("Energy");

            yAxis4.IsVisible = true;
            myPane.Y2AxisList.Add(yAxis4);
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis4.MajorTic.IsInside   = false;
            yAxis4.MinorTic.IsInside   = false;
            yAxis4.MajorTic.IsOpposite = false;
            yAxis4.MinorTic.IsOpposite = false;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis4.Scale.Align = AlignP.Inside;
            yAxis4.Type        = AxisType.Log;
            yAxis4.Scale.Min   = 100;

            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);

            base.ZedGraphControl.AxisChange();
        }
Exemplo n.º 22
0
        // Call this method from the Form_Load method, passing your ZedGraphControl instance
        private void CreateMultiYChart(ZedGraphControl zgc)
        {
            // Get a reference to the GraphPane
            GraphPane myPane = zgc.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text        = "Demonstration of Multi Y Graph";
            myPane.XAxis.Title.Text  = "Time, s";
            myPane.YAxis.Title.Text  = "Velocity, m/s";
            myPane.Y2Axis.Title.Text = "Acceleration, m/s2";

            // Make up some data points based on the Sine function
            PointPairList vList = new PointPairList();
            PointPairList aList = new PointPairList();
            PointPairList dList = new PointPairList();
            PointPairList eList = new PointPairList();

            double[] x4 = { 0, 1, 2, 3, 4, 5, 6, 7 };

            /*
             * // Fabricate some data values
             * for (int i = 0; i < 7; i++)
             * {
             *  double time = (double)i;
             *  double acceleration = 2.0;
             *  double velocity = acceleration * time;
             *  double distance = acceleration * time * time / 2.0;
             *  double energy = 100.0 * velocity * velocity / 2.0;
             *  aList.Add(time, acceleration);
             * }
             *
             *
             * for (int i = 0; i < 5; i++)
             * {
             *  double time = x4[i];
             *  double acceleration = 2.0;
             *  double velocity = 13.0 + 7.0 * acceleration * time;
             *  double distance = 10.0 + 3.0 * acceleration * time * velocity;
             *  double energy = 8.0 + 6.0 * velocity * velocity / 2.0;
             *  vList.Add(x4[i], velocity);
             *  eList.Add(x4[i], energy);
             *  dList.Add(x4[i], distance);
             * }
             */

            // Generate a red curve with diamond symbols, and "Velocity" in the legend
            LineItem myCurve = myPane.AddCurve("Velocity",
                                               // dList, Color.Red, SymbolType.Diamond);
                                               DEPValueList, Color.Red, SymbolType.Diamond);

            // Fill the symbols with white
            //myCurve.Symbol.Size = 4.0F;
            myCurve.Symbol.Fill = new Fill(Color.White);
            myCurve.Line.Width  = 4.0F;

            // Generate a green curve with square symbols, and "Distance" in the legend
            myCurve = myPane.AddCurve("Distance",
                                      // vList, Color.Green, SymbolType.Square);
                                      ANXValueList, Color.Green, SymbolType.Square);
            // Fill the symbols with white
            //myCurve.Symbol.Size = 4.0F;
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 1;
            myCurve.Line.Width = 4.0F;

            // Generate a Black curve with triangle symbols, and "Energy" in the legend
            myCurve = myPane.AddCurve("Energy",
                                      //   eList, Color.Black, SymbolType.Triangle);
                                      HMAValueList, Color.Black, SymbolType.Triangle);
            // Fill the symbols with white
            //myCurve.Symbol.Size = 4.0F;
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = false;
            // Associate this curve with the second Y2 axis
            myCurve.YAxisIndex = 1;
            myCurve.Line.Width = 4.0F;



            //double[] x4 = { 0, 1, 2, 3, 4, 5, 6, 7 };
            // double[] x5 = { 10,11,12,13,14,15,16,17};
            double[] y4 = { 30, 45, 53, 60, 45, 53, 24 };
            // normalize(y4, 7);
            BarItem bar = myPane.AddBar("PHI", x4, y5, Color.SteelBlue);

            // Fill the bars with a RosyBrown-White-RosyBrown gradient
            bar.Bar.Border.Width = 0F;
            bar.Bar.Fill         = new Fill(Color.LightBlue, Color.White, Color.LightBlue);


            //// Generate a blue curve with circle symbols, and "Acceleration" in the legend
            //myCurve = myPane.AddCurve("Acceleration",
            //   aList, Color.Blue, SymbolType.Circle);
            //// Fill the symbols with white
            //myCurve.Symbol.Fill = new Fill(Color.White);
            //// Associate this curve with the Y2 axis
            //myCurve.IsY2Axis = true;


            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = false;

            myPane.Border.IsVisible = false;
            myPane.XAxis.IsVisible  = false;

            myPane.XAxis.Scale.Min = -1;
            myPane.XAxis.Scale.Max = 7;

            myPane.Legend.IsVisible = false;//legend:图例、说明
            myPane.Title.IsVisible  = false;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max   = 1.5;//我把这里的100改成了1.5
            myPane.YAxis.IsVisible   = false;

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = false;
            // Make the Y2 axis scale blue
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = false;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            myPane.Y2Axis.Scale.Min   = 0;   //我把1.5改成了0
            myPane.Y2Axis.Scale.Max   = 1.5; //我把3改成了1.5

            // Create a second Y Axis, green
            YAxis yAxis3 = new YAxis("Distance, m");

            myPane.YAxisList.Add(yAxis3);
            yAxis3.IsVisible = false;
            yAxis3.Scale.FontSpec.FontColor = Color.Green;
            yAxis3.Title.FontSpec.FontColor = Color.Green;
            yAxis3.Color = Color.Green;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis3.MajorTic.IsInside   = false;
            yAxis3.MinorTic.IsInside   = false;
            yAxis3.MajorTic.IsOpposite = false;
            yAxis3.MinorTic.IsOpposite = false;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis3.Scale.Align = AlignP.Inside;

            Y2Axis yAxis4 = new Y2Axis("Energy");

            yAxis4.IsVisible = false;
            myPane.Y2AxisList.Add(yAxis4);
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis4.MajorTic.IsInside   = false;
            yAxis4.MinorTic.IsInside   = false;
            yAxis4.MajorTic.IsOpposite = false;
            yAxis4.MinorTic.IsOpposite = false;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis4.Scale.Align = AlignP.Inside;
            yAxis4.Type        = AxisType.Log;
            yAxis4.Scale.Min   = 1.5;//我把100改成1.5

            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);

            zgc.AxisChange();
        }
Exemplo n.º 23
0
 /// <summary>
 /// Add a secondary <see cref="Y2Axis" /> (right side) to the list of axes
 /// in the Graph.
 /// </summary>
 /// <remarks>
 /// Note that the primary <see cref="Y2Axis" /> is always included by default.
 /// This method turns off the <see cref="MajorTic" /> and <see cref="MinorTic" />
 /// <see cref="MinorTic.IsOpposite" /> and <see cref="MinorTic.IsInside" />
 /// properties by default.
 /// </remarks>
 /// <param name="title">The title for the <see cref="Y2Axis" />.</param>
 /// <returns>the ordinal position (index) in the <see cref="Y2AxisList" />.</returns>
 public int AddY2Axis( string title )
 {
     Y2Axis axis = new Y2Axis( title );
     axis.MajorTic.IsOpposite = false;
     axis.MinorTic.IsOpposite = false;
     axis.MajorTic.IsInside = false;
     axis.MinorTic.IsInside = false;
     _y2AxisList.Add( axis );
     return _y2AxisList.Count - 1;
 }
Exemplo n.º 24
0
        private void chart_initial()
        {
            //禁止主界面的放大、缩小以及滑轮功能
            zedGraphControl1.IsShowContextMenu = false;
            zedGraphControl1.IsEnableHPan      = false; zedGraphControl1.IsEnableVPan = false;
            zedGraphControl1.IsEnableHZoom     = false; zedGraphControl1.IsEnableZoom = false;
            GraphPane myPane = zedGraphControl1.GraphPane;

            //曲线面板属性
            //myPane.Fill = new Fill(Color.FromArgb(28, 29, 31));
            //  myPane.Fill = new Fill(Color.Black);
            //  myPane.Chart.Fill = new Fill(Color.Black);
            myPane.Chart.Border.Color = Color.Gray;
            myPane.IsFontsScaled      = false;
            myPane.Border.Color       = Color.White;
            myPane.Legend.IsVisible   = false;
            myPane.Title.Text         = " ";
            //x轴
            myPane.XAxis.Title.Text               = "时间(分钟)";
            myPane.XAxis.MajorGrid.Color          = Color.Black;
            myPane.XAxis.Scale.FontSpec.FontColor = Color.Black;
            myPane.XAxis.Scale.FontSpec.Size      = 15;
            myPane.XAxis.Title.FontSpec.Size      = 15;
            myPane.XAxis.Title.FontSpec.FontColor = Color.Black;
            myPane.XAxis.Scale.Min           = 0;  //X轴最小值0
            myPane.XAxis.Scale.Max           = 30; //X轴最大30
            myPane.XAxis.MajorTic.IsInside   = false;
            myPane.XAxis.MinorTic.IsInside   = false;
            myPane.XAxis.MajorTic.IsOpposite = false;
            myPane.XAxis.MinorTic.IsOpposite = false;
            myPane.XAxis.MajorTic.Color      = Color.White;
            myPane.XAxis.MinorTic.Color      = Color.White;
            myPane.XAxis.Scale.MajorStep     = 5;//X轴大步长为5,也就是显示文字的大间隔
            //y轴
            myPane.YAxis.MajorTic.IsInside  = false;
            myPane.YAxis.MajorGrid.Color    = Color.White;
            myPane.YAxis.MinorTic.IsInside  = false;
            myPane.Y2Axis.MajorTic.IsInside = false;
            myPane.Y2Axis.MajorGrid.Color   = Color.White;
            myPane.Y2Axis.MinorTic.IsInside = false;


            // 添加6条曲线
            PointPairList List1 = new PointPairList();
            PointPairList List2 = new PointPairList();
            PointPairList List3 = new PointPairList();
            PointPairList List4 = new PointPairList();
            PointPairList List5 = new PointPairList();
            PointPairList List6 = new PointPairList();

            // 第1条线的标号为3
            LineItem myCurve = myPane.AddCurve(paraLine3.Tagname,
                                               List1, Color.Blue, SymbolType.None);

            myCurve.Line.Width = 1;
            // Fill the symbols with white
            // myCurve.Symbol.Fill = new Fill(Color.White);

            //第2条线的标号为4
            myCurve = myPane.AddCurve(paraLine4.Tagname,
                                      List2, Color.Lime, SymbolType.None);
            myCurve.Line.Width = 1;
            // Fill the symbols with white
            // myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;

            // 第3条线的标号为2
            myCurve = myPane.AddCurve(paraLine2.Tagname,
                                      List3, Color.Yellow, SymbolType.None);
            myCurve.Line.Width = 1;
            // Fill the symbols with white
            //   myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 1;

            // 第4条线的标号为5
            myCurve = myPane.AddCurve(paraLine5.Tagname,
                                      List4, Color.SeaGreen, SymbolType.None);
            myCurve.Line.Width = 1;
            // Fill the symbols with white
            //myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;
            // Associate this curve with the second Y2 axis
            myCurve.YAxisIndex = 1;

            // 第5条线的标号为1
            myCurve = myPane.AddCurve(paraLine1.Tagname,
                                      List5, Color.Red, SymbolType.None);
            myCurve.Line.Width = 1;
            // Fill the symbols with white
            //  myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 2;

            // 第6条线的标号为6
            myCurve = myPane.AddCurve(paraLine6.Tagname,
                                      List6, Color.SkyBlue, SymbolType.None);
            myCurve.Line.Width = 1;
            // Fill the symbols with white
            //  myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;
            // Associate this curve with the second Y2 axis
            myCurve.YAxisIndex = 2;


            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // 6条y轴的颜色,文字大小等相关属性
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.YAxis.Scale.FontSpec.Size      = 15;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Blue;
            myPane.YAxis.Title.FontSpec.Size      = 15;
            myPane.YAxis.Color = Color.Blue;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MajorTic.Color      = Color.Blue;
            myPane.YAxis.MinorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.Color      = Color.Blue;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max   = int.Parse(paraLine3.Max);
            myPane.YAxis.Scale.Min   = int.Parse(paraLine3.Min);


            // Enable the Y2 axis Lime
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale black
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Lime;
            myPane.Y2Axis.Scale.FontSpec.Size      = 15;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Lime;
            myPane.Y2Axis.Title.FontSpec.Size      = 15;
            myPane.Y2Axis.Color = Color.Lime;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MajorTic.Color      = Color.Lime;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.Color      = Color.Lime;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            myPane.Y2Axis.Scale.Max   = int.Parse(paraLine4.Max);
            myPane.Y2Axis.Scale.Min   = int.Parse(paraLine4.Min);

            // Create a second Y Axis, Yellow
            YAxis yAxis3 = new YAxis(paraLine2.Tagname + "(" + paraLine2.Unit + ")");

            myPane.YAxisList.Add(yAxis3);
            yAxis3.Scale.FontSpec.FontColor = Color.Yellow;
            yAxis3.Scale.FontSpec.Size      = 15;
            yAxis3.Title.FontSpec.FontColor = Color.Yellow;
            yAxis3.Title.FontSpec.Size      = 15;
            yAxis3.Color = Color.Yellow;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis3.MajorTic.IsInside   = false;
            yAxis3.MinorTic.IsInside   = false;
            yAxis3.MajorTic.IsOpposite = false;
            yAxis3.MajorTic.Color      = Color.Yellow;
            yAxis3.MinorTic.IsOpposite = false;
            yAxis3.MinorTic.Color      = Color.Yellow;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis3.Scale.Align = AlignP.Inside;
            yAxis3.Scale.Max   = int.Parse(paraLine2.Max);
            yAxis3.Scale.Min   = int.Parse(paraLine2.Min);


            // Create a third Y Axis, red
            YAxis yAxis5 = new YAxis(paraLine1.Tagname + "(" + paraLine1.Unit + ")");

            myPane.YAxisList.Add(yAxis5);
            yAxis5.Scale.FontSpec.FontColor = Color.Red;
            yAxis5.Scale.FontSpec.Size      = 15;
            yAxis5.Title.FontSpec.FontColor = Color.Red;
            yAxis5.Title.FontSpec.Size      = 15;
            yAxis5.Color = Color.Red;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis5.MajorTic.IsInside   = false;
            yAxis5.MinorTic.IsInside   = false;
            yAxis5.MajorTic.IsOpposite = false;
            yAxis5.MajorTic.Color      = Color.Red;
            yAxis5.MinorTic.IsOpposite = false;
            yAxis5.MinorTic.Color      = Color.Red;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis5.Scale.Align = AlignP.Inside;
            yAxis5.Scale.Max   = int.Parse(paraLine1.Max);
            yAxis5.Scale.Min   = int.Parse(paraLine1.Min);


            // Create a second Y2 Axis, green
            Y2Axis yAxis4 = new Y2Axis(paraLine5.Tagname + "(" + paraLine5.Unit + ")");

            yAxis4.IsVisible = true;
            myPane.Y2AxisList.Add(yAxis4);
            yAxis4.Scale.FontSpec.FontColor = Color.SeaGreen;
            yAxis4.Scale.FontSpec.Size      = 15;
            yAxis4.Title.FontSpec.FontColor = Color.SeaGreen;
            yAxis4.Title.FontSpec.Size      = 15;
            yAxis4.Color = Color.SeaGreen;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis4.MajorTic.IsInside   = false;
            yAxis4.MinorTic.IsInside   = false;
            yAxis4.MajorTic.IsOpposite = false;
            yAxis4.MajorTic.Color      = Color.SeaGreen;
            yAxis4.MinorTic.IsOpposite = false;
            yAxis4.MinorTic.Color      = Color.SeaGreen;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis4.Scale.Align = AlignP.Inside;
            yAxis4.Scale.Max   = int.Parse(paraLine5.Max);
            yAxis4.Scale.Min   = int.Parse(paraLine5.Min);

            // Create a third Y2 Axis, Skyblue
            Y2Axis yAxis6 = new Y2Axis(paraLine6.Tagname + "(" + paraLine6.Unit + ")");

            yAxis6.IsVisible = true;
            myPane.Y2AxisList.Add(yAxis6);
            yAxis6.Scale.FontSpec.FontColor = Color.SkyBlue;
            yAxis6.Scale.FontSpec.Size      = 15;
            yAxis6.Title.FontSpec.FontColor = Color.SkyBlue;
            yAxis6.Title.FontSpec.Size      = 15;
            yAxis6.Color = Color.SkyBlue;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis6.MajorTic.IsInside   = false;
            yAxis6.MinorTic.IsInside   = false;
            yAxis6.MajorTic.IsOpposite = false;
            yAxis6.MajorTic.Color      = Color.SkyBlue;
            yAxis6.MinorTic.IsOpposite = false;
            yAxis6.MinorTic.Color      = Color.SkyBlue;
            // Align the Y2 axis labels so they are flush to the axis
            yAxis6.Scale.Align = AlignP.Inside;
            yAxis6.Scale.Max   = int.Parse(paraLine6.Max);
            yAxis6.Scale.Min   = int.Parse(paraLine6.Min);
            // Fill the axis background with a gradient
            //  myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);

            //新增,y轴不显示名称及零线
            foreach (YAxis y in myPane.YAxisList)
            {
                y.MajorGrid.IsZeroLine = false;
                y.Title.IsVisible      = false;
            }
            foreach (Y2Axis y in myPane.Y2AxisList)
            {
                y.MajorGrid.IsZeroLine = false;
                y.Title.IsVisible      = false;
            }
            //新增,读取配置文件的曲线颜色信息,更新曲线
            trend_refresh("1"); trend_refresh("2"); trend_refresh("3");
            trend_refresh("4"); trend_refresh("5"); trend_refresh("6");
            zedGraphControl1.AxisChange();
        }
Exemplo n.º 25
0
        private void printresults(List <double> eta, List <double> power, List <double> gamma, int fanType)
        {
            double fand  = 0;
            double fanrs = 0;

            if (fanType == 1) //Light duty
            {
                this.fanTypeL.Text = "Light duty";
                fand  = 0.508;
                fanrs = 1241;
            }
            else if (fanType == 2)
            {
                this.fanTypeL.Text = "Medium duty";
                fand  = 1.0668;
                fanrs = 524;
            }
            else if (fanType == 3)
            {
                this.fanTypeL.Text = "Heavy duty";
                fand  = 1.524;
                fanrs = 496;
            }
            else if (fanType == 0)
            {
                this.fanTypeL.Text = "No fan";
            }

            if (fanType != 0)
            {
                this.fanDiameterL.Text = fand.ToString();
                if (datapackage.bldgtype == 0 || datapackage.bldgtype == 1)
                {
                    this.noOfFansL.Text = (Math.Floor(datapackage.topwindowsize / (Math.PI / 4 * Math.Pow(fand, 2)))).ToString();
                }
                else if (datapackage.bldgtype == 2)
                {
                    this.noOfFansL.Text = (Math.Floor(datapackage.sidewindowsize / (Math.PI / 4 * Math.Pow(fand, 2)))).ToString();
                }

                if (datapackage.transimu == 0) //SS
                {
                }
                else
                {
                    double[] eff    = new double[24];
                    double[] pow    = new double[24];
                    double[] sp     = new double[24];
                    double[] time   = new double[24];
                    int      i      = 0;
                    double   maxeff = 0;
                    double   maxpow = 0;
                    double   maxsp  = 0;
                    double   avgeff = 0;
                    double   avgsp  = 0;
                    double   totpow = 0;

                    for (int linea = 39; linea <= 40 * 24 - 1; linea += 40)
                    {
                        eff[i]  = eta[linea] * 100;
                        avgeff += eff[i] / 24;
                        pow[i]  = power[linea] / 1000;
                        totpow += pow[i];
                        sp[i]   = (1 / gamma[linea]) * fanrs;
                        avgsp  += sp[i] / 24;
                        if (eff[i] > maxeff)
                        {
                            maxeff = eff[i];
                        }
                        if (pow[i] > maxpow)
                        {
                            maxpow = pow[i];
                        }
                        if (sp[i] > maxsp)
                        {
                            maxsp = sp[i];
                        }
                        time[i] = ++i;
                    }

                    this.fanOSL.Text    = (Math.Round(avgsp)).ToString();
                    this.fanPowerL.Text = (Math.Round(totpow)).ToString();
                    this.fanEtaL.Text   = (Math.Round(avgeff)).ToString();

                    gPFanResults = FanCurvePane.GraphPane;

                    // Set the title and axis labels
                    gPFanResults.Title.IsVisible   = false;
                    gPFanResults.XAxis.Title.Text  = "Time of a day, starting from midnight [hr]";
                    gPFanResults.YAxis.Title.Text  = "Electric consumption [kW]";
                    gPFanResults.Y2Axis.Title.Text = "Operational speed [rpm]";
                    Y2Axis yAxis2 = new Y2Axis("Efficiency [%]");
                    gPFanResults.Y2AxisList.Add(yAxis2);
                    gPFanResults.Y2Axis.IsVisible = true;
                    yAxis2.IsVisible   = true;
                    yAxis2.Scale.Align = AlignP.Inside;

                    //Chart format
                    gPFanResults.Fill       = new Fill(Color.WhiteSmoke, Color.Lavender, 0F);
                    gPFanResults.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245),
                                                       Color.FromArgb(255, 255, 190), 90F);
                    gPFanResults.XAxis.MajorGrid.IsVisible = true;

                    //Plot curves
                    lIFanPower            = gPFanResults.AddCurve("Electric consumption", time, pow, Color.Green, SymbolType.None);
                    lIFanPower.Line.Width = 2.0F;
                    //lIFanPower.Line.IsSmooth = true;
                    lIFanSpeed            = gPFanResults.AddCurve("Speed", time, sp, Color.Red, SymbolType.None);
                    lIFanSpeed.IsY2Axis   = true;
                    lIFanSpeed.Line.Width = 2.0F;
                    //lIFanSpeed.Line.IsSmooth = true;
                    lIFanEfficiency            = gPFanResults.AddCurve("Efficiency", time, eff, Color.Blue, SymbolType.None);
                    lIFanEfficiency.Line.Width = 2.0F;
                    //lIFanEfficiency.Line.IsSmooth = true;
                    lIFanEfficiency.IsY2Axis   = true;
                    lIFanEfficiency.YAxisIndex = 1;

                    //Axis format
                    gPFanResults.YAxis.MajorTic.IsOpposite  = false;
                    gPFanResults.Y2Axis.MajorTic.IsOpposite = false;
                    gPFanResults.YAxis.MinorTic.IsOpposite  = false;
                    gPFanResults.Y2Axis.MinorTic.IsOpposite = false;
                    yAxis2.MinorTic.IsOpposite = false;
                    yAxis2.MajorTic.IsOpposite = false;

                    gPFanResults.YAxis.Scale.FontSpec.FontColor = Color.Green;
                    gPFanResults.YAxis.Title.FontSpec.FontColor = Color.Green;

                    gPFanResults.Y2Axis.Title.FontSpec.FontColor = Color.Red;
                    gPFanResults.Y2Axis.Scale.FontSpec.FontColor = Color.Red;

                    yAxis2.Title.FontSpec.FontColor = Color.Blue;
                    yAxis2.Scale.FontSpec.FontColor = Color.Blue;

                    gPFanResults.YAxis.Scale.MajorStepAuto = false;
                    gPFanResults.YAxis.Scale.MinorStepAuto = false;
                    gPFanResults.YAxis.Scale.Max           = maxpow * 1.1;
                    gPFanResults.YAxis.Scale.Min           = 0;
                    gPFanResults.YAxis.Scale.MajorStep     = maxpow * 1.1 / 4;
                    gPFanResults.YAxis.Scale.MinorStep     = maxpow * 1.1 / 8;

                    gPFanResults.Y2Axis.Scale.MajorStepAuto = false;
                    gPFanResults.Y2Axis.Scale.MinorStepAuto = false;
                    gPFanResults.Y2Axis.Scale.Max           = maxsp * 2;
                    gPFanResults.Y2Axis.Scale.Min           = 0;
                    gPFanResults.Y2Axis.Scale.MajorStep     = maxsp * 2 / 4;
                    gPFanResults.Y2Axis.Scale.MinorStep     = maxsp * 2 / 8;

                    yAxis2.Scale.MajorStepAuto = false;
                    yAxis2.Scale.MajorStepAuto = false;
                    yAxis2.Scale.Max           = 100;
                    yAxis2.Scale.Min           = 0;
                    yAxis2.Scale.MajorStep     = 20;
                    yAxis2.Scale.MinorStep     = 10;

                    gPFanResults.XAxis.Scale.MajorStepAuto = false;
                    gPFanResults.XAxis.Scale.Format        = "0#";
                    gPFanResults.XAxis.Scale.Max           = 25;
                    gPFanResults.XAxis.Scale.Min           = 0;
                    gPFanResults.XAxis.Scale.MajorStep     = 5;
                    gPFanResults.XAxis.Scale.MinorStep     = 1;
                }
            }
            else
            {
                this.noOfFansL.Text       = "0";
                this.fanOSL.Text          = "0";
                this.fanPowerL.Text       = "0";
                this.fanEtaL.Text         = "0";
                this.fanDiameterL.Text    = "0";
                this.FanCurvePane.Visible = false;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// 初始化样式布局(默认为直角坐标,无图例)
        /// </summary>
        /// <param name="g"></param>
        /// <param name="xa"></param>
        /// <param name="ya"></param>
        /// <param name="y2a"></param>
        /// <param name="gd"></param>
        /// <param name="lb"></param>
        /// <param name="tl"></param>
        internal void AddChartStyle(Graphics g, Title tl, XYLabel lb, Grid gd, XAxis xa, YAxis ya, Y2Axis y2a)
        {
            //设置绘图区位置、大小
            SetPlotArea(g, tl, lb, gd, xa, ya, y2a);
            //ChartArea和PlotArea底色绘制(通用)
            FillColorInChartAreas(g);
            //直角坐标通用网格线
            AddGirdSquare(g, gd, xa, ya);

            //绘制x,y,y2 轴刻度线和标记
            float      fX, fY;
            SolidBrush aBrush = new SolidBrush(xa.XTickStyle.TextColor);

            for (fX = xa.XLimMin; fX <= xa.XLimMax; fX += xa.XTick)
            {
                fX = DataDeal.FloatAccur(fX);
                PointF yAxisPoint = Point2D(new PointF(fX, ya.YLimMin), xa, ya);
                g.DrawLine(Pens.Black, yAxisPoint, new PointF(yAxisPoint.X, yAxisPoint.Y - 5f));

                StringFormat sFormat = new StringFormat();
                sFormat.Alignment = StringAlignment.Far;
                SizeF sizeXTick = g.MeasureString(fX.ToString(), xa.XTickStyle.TextFont);
                g.DrawString(fX.ToString(), xa.XTickStyle.TextFont, aBrush, new PointF(yAxisPoint.X + sizeXTick.Width / 2, yAxisPoint.Y + 4f), sFormat);
            }

            aBrush = new SolidBrush(ya.YTickStyle.TextColor);
            SizeF tickFontSize = g.MeasureString("A", ya.YTickStyle.TextFont);

            for (fY = ya.YLimMin; fY <= ya.YLimMax; fY += ya.YTick)
            {
                fY = DataDeal.FloatAccur(fY);
                PointF xAxisPoint = Point2D(new PointF(xa.XLimMin, fY), xa, ya);
                g.DrawLine(Pens.Black, xAxisPoint, new PointF(xAxisPoint.X + 5f, xAxisPoint.Y));

                StringFormat sFormat = new StringFormat();
                sFormat.Alignment = StringAlignment.Far;
                g.DrawString(fY.ToString(), ya.YTickStyle.TextFont, aBrush, new PointF(xAxisPoint.X - 3f, xAxisPoint.Y - tickFontSize.Height / 2), sFormat);
            }

            if (y2a.IsY2Axis)
            {
                aBrush       = new SolidBrush(y2a.Y2TickStyle.TextColor);
                tickFontSize = g.MeasureString("A", y2a.Y2TickStyle.TextFont);
                for (fY = y2a.Y2LimMin; fY <= y2a.Y2LimMax; fY += y2a.Y2Tick)
                {
                    fY = DataDeal.FloatAccur(fY);
                    PointF x2AxisPoint = Point2DY2(new PointF(xa.XLimMax, fY), xa, y2a);
                    g.DrawLine(Pens.Black, x2AxisPoint, new PointF(x2AxisPoint.X - 5f, x2AxisPoint.Y));

                    StringFormat sFormat = new StringFormat();
                    sFormat.Alignment = StringAlignment.Near;
                    g.DrawString(fY.ToString(), y2a.Y2TickStyle.TextFont, aBrush, new PointF(x2AxisPoint.X + 3f, x2AxisPoint.Y - tickFontSize.Height / 2), sFormat);
                }
            }
            aBrush.Dispose();

            AddTitle(g, tl);
            AddLabels(g, tl, lb, y2a);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 设置绘图的样式
        /// </summary>
        private void setTitle(OutputCurveEntity outPutCurve)
        {
            GraphPane myPane = _zedGraphOutputCurve.GraphPane;

            string XAxisTitle = string.Empty;//坐标轴名称

            if (string.IsNullOrEmpty(outPutCurve.X.Unit))
            {
                XAxisTitle = outPutCurve.X.AxisName;//设置Y轴的坐标的名称
            }
            else
            {
                if (outPutCurve.X.Unit.Contains("/"))                                      //符合复合坐标的形式
                {
                    XAxisTitle = outPutCurve.X.AxisName + "/(" + outPutCurve.X.Unit + ")"; //设置Y轴的坐标的名称
                }
                else
                {
                    XAxisTitle = outPutCurve.X.AxisName + "/" + outPutCurve.X.Unit;//设置Y轴的坐标的名称
                }
            }

            myPane.XAxis.Title.Text     = XAxisTitle;
            myPane.XAxis.Title.FontSpec = this.fontSpec;


            #region "设置X轴上下限"
            if (outPutCurve.X.dDownLimit == null)
            {
                myPane.XAxis.Scale.MinAuto = true;
            }
            else
            {
                myPane.XAxis.Scale.Min = outPutCurve.X.dDownLimit.Value;
            }

            if (outPutCurve.X.dUpLimit == null)
            {
                myPane.XAxis.Scale.MaxAuto = true;
            }
            else
            {
                myPane.XAxis.Scale.Max = outPutCurve.X.dUpLimit.Value;
            }
            #endregion


            foreach (var curve in outPutCurve.Curves)//同一个X轴,含有多个相同的Y轴
            {
                #region
                LineItem CurveLine = null;
                switch (_iSymbolType)
                {
                case 0:
                    CurveLine = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Square);   //添加一条曲线
                    break;

                case 1:
                    CurveLine             = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Square);//添加一条曲线
                    CurveLine.Symbol.Fill = new Fill(Color.Black);
                    break;

                case 2:
                    CurveLine = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Circle);    //添加一条曲线
                    break;

                case 3:
                    CurveLine             = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Circle);//添加一条曲线
                    CurveLine.Symbol.Fill = new Fill(Color.Black);
                    break;

                //case 5:
                //    CurveLine = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Diamond);//添加一条曲线
                //    break;
                //case 6:
                //    CurveLine = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Diamond);//添加一条曲线
                //    CurveLine.Symbol.Fill = new Fill(Color.Black);
                //    break;
                case 4:
                    CurveLine = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Triangle);    //添加一条曲线
                    break;

                case 5:
                    CurveLine             = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, SymbolType.Triangle);//添加一条曲线
                    CurveLine.Symbol.Fill = new Fill(Color.Black);
                    break;

                default:
                    CurveLine = myPane.AddCurve(curve.Key.CurveName, curve.Value, Color.Black, (SymbolType)_iSymbolType);    //添加一条曲线
                    break;
                }
                _iSymbolType++;
                CurveLine.Line.IsSmooth      = true;
                CurveLine.Line.SmoothTension = 0.5F; //设置曲线的平滑度
                CurveLine.Label.IsVisible    = true; //SymbolType.Diamond;


                #endregion

                string AxisTitle = string.Empty;//坐标轴名称
                if (string.IsNullOrEmpty(curve.Key.Unit))
                {
                    AxisTitle = curve.Key.AxisName;//设置Y轴的坐标的名称
                }
                else
                {
                    if (curve.Key.Unit.Contains("/"))                                 //符合复合坐标的形式
                    {
                        AxisTitle = curve.Key.AxisName + "/(" + curve.Key.Unit + ")"; //设置Y轴的坐标的名称
                    }
                    else
                    {
                        AxisTitle = curve.Key.AxisName + "/" + curve.Key.Unit;//设置Y轴的坐标的名称
                    }
                }

                switch (curve.Key.EAxis)//设置Y坐标轴
                {
                case EnumAxis.YL1:
                    CurveLine.YAxisIndex = 0;

                    myPane.YAxis.Title.Text                      = AxisTitle;
                    myPane.YAxis.Title.FontSpec.IsBold           = false;
                    myPane.YAxis.Title.FontSpec.Size             = 12f;
                    myPane.YAxis.Title.FontSpec.Family           = "仿宋;Times New Roman";
                    myPane.YAxis.Title.FontSpec.Border.IsVisible = false;


                    myPane.YAxis.Scale.Align = AlignP.Inside;

                    if (curve.Key.dDownLimit == null)
                    {
                        myPane.YAxis.Scale.MinAuto = true;
                    }
                    else
                    {
                        myPane.YAxis.Scale.Min = curve.Key.dDownLimit.Value;
                    }

                    if (curve.Key.dUpLimit == null)
                    {
                        myPane.YAxis.Scale.MaxAuto = true;
                    }
                    else
                    {
                        myPane.YAxis.Scale.Max = curve.Key.dUpLimit.Value;
                    }

                    break;

                case EnumAxis.YL2:
                case EnumAxis.YL3:
                    YAxis yAxisYL = myPane.YAxisList.Where(o => o.Title.Text == AxisTitle).FirstOrDefault();

                    if (yAxisYL == null)    //判断坐标轴上是否已经添加比例尺
                    {
                        yAxisYL = new YAxis(AxisTitle);

                        yAxisYL.Scale.Align = AlignP.Inside;
                        myPane.YAxisList.Add(yAxisYL);
                    }
                    yAxisYL.Title.FontSpec.IsBold           = false;
                    yAxisYL.Title.FontSpec.Size             = 12f;
                    yAxisYL.Title.FontSpec.Family           = "仿宋;Times New Roman";
                    yAxisYL.Title.FontSpec.Border.IsVisible = false;

                    if (EnumAxis.YL2 == curve.Key.EAxis)
                    {
                        CurveLine.YAxisIndex = 1;
                    }
                    else if (EnumAxis.YL3 == curve.Key.EAxis)
                    {
                        CurveLine.YAxisIndex = 2;
                    }

                    if (curve.Key.dDownLimit == null)
                    {
                        yAxisYL.Scale.MinAuto = true;
                    }
                    else
                    {
                        yAxisYL.Scale.Min = curve.Key.dDownLimit.Value;
                    }

                    if (curve.Key.dUpLimit == null)
                    {
                        yAxisYL.Scale.MaxAuto = true;
                    }
                    else
                    {
                        yAxisYL.Scale.Max = curve.Key.dUpLimit.Value;
                    }
                    break;

                case EnumAxis.YR1:

                    CurveLine.IsY2Axis   = true;
                    CurveLine.YAxisIndex = 0;

                    myPane.Y2Axis.IsVisible                       = true;
                    myPane.Y2Axis.Title.Text                      = AxisTitle;
                    myPane.Y2Axis.Title.FontSpec.IsBold           = false;
                    myPane.Y2Axis.Title.FontSpec.Size             = 12f;
                    myPane.Y2Axis.Title.FontSpec.Family           = "仿宋;Times New Roman";
                    myPane.Y2Axis.Title.FontSpec.Border.IsVisible = false;
                    myPane.Y2Axis.Scale.Align                     = AlignP.Inside;

                    myPane.Y2Axis.MajorTic.IsInside   = false;
                    myPane.Y2Axis.MinorTic.IsInside   = false;
                    myPane.Y2Axis.MajorTic.IsOpposite = false;
                    myPane.Y2Axis.MinorTic.IsOpposite = false;

                    myPane.Y2Axis.Scale.Align = AlignP.Inside;

                    if (curve.Key.dDownLimit == null)
                    {
                        myPane.Y2Axis.Scale.MinAuto = true;
                    }
                    else
                    {
                        myPane.Y2Axis.Scale.Min = curve.Key.dDownLimit.Value;
                    }

                    if (curve.Key.dUpLimit == null)
                    {
                        myPane.Y2Axis.Scale.MaxAuto = true;
                    }
                    else
                    {
                        myPane.Y2Axis.Scale.Max = curve.Key.dUpLimit.Value;
                    }
                    break;

                case EnumAxis.YR2:
                case EnumAxis.YR3:

                    Y2Axis yAxisYR = myPane.Y2AxisList.Where(o => o.Title.Text == AxisTitle).FirstOrDefault();

                    if (yAxisYR == null)
                    {
                        yAxisYR = new Y2Axis(AxisTitle);
                        myPane.Y2AxisList.Add(yAxisYR);
                        CurveLine.IsY2Axis = true;
                    }
                    if (EnumAxis.YR2 == curve.Key.EAxis)
                    {
                        CurveLine.YAxisIndex = 1;
                    }
                    else if (EnumAxis.YR3 == curve.Key.EAxis)
                    {
                        CurveLine.YAxisIndex = 2;
                    }

                    yAxisYR.IsVisible                       = true;
                    yAxisYR.Title.FontSpec.IsBold           = false;
                    yAxisYR.Title.FontSpec.Size             = 12f;
                    yAxisYR.Title.FontSpec.Family           = "仿宋;Times New Roman";
                    yAxisYR.Title.FontSpec.Border.IsVisible = false;

                    if (curve.Key.dDownLimit == null)
                    {
                        yAxisYR.Scale.MinAuto = true;
                    }
                    else
                    {
                        yAxisYR.Scale.Min = curve.Key.dDownLimit.Value;
                    }

                    if (curve.Key.dUpLimit == null)
                    {
                        yAxisYR.Scale.MaxAuto = true;
                    }
                    else
                    {
                        yAxisYR.Scale.Max = curve.Key.dUpLimit.Value;
                    }

                    break;
                }
            }
        }
Exemplo n.º 28
0
        //绘制线性图
        internal static void AddLines(DataCollection dc, Graphics g, ChartStyle cs, XAxis xa, YAxis ya, Y2Axis y2a)
        {
            if (dc.ChartType != Chart2DTypeEnum.LineChart || dc.DataSeriesList.Count == 0)
            {
                return;
            }
            //SeriesColor.SetSeriesColor(dc);

            // Plot lines:
            foreach (DataSeries ds in dc.DataSeriesList)
            {
                if (ds.LineStyle.IsVisible == true)
                {
                    PointF pt  = new PointF();
                    PointF pt0 = new PointF();

                    Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.LineThickness);
                    aPen.DashStyle = ds.LineStyle.LinePattern;

                    #region line
                    // Plot Line:
                    if (ds.LineChartType == LineChartTypeEnum.Line)
                    {
                        for (int i = 1; i < ds.PointList.Count; i++)
                        {
                            if (!ds.IsY2Data)
                            {
                                g.DrawLine(aPen, cs.Point2D((PointF)ds.PointList[i - 1], xa, ya),
                                           cs.Point2D((PointF)ds.PointList[i], xa, ya));
                            }
                            else
                            {
                                g.DrawLine(aPen, cs.Point2DY2((PointF)ds.PointList[i - 1], xa, y2a),
                                           cs.Point2DY2((PointF)ds.PointList[i], xa, y2a));
                            }
                        }
                    }
                    // Plot Spline:
                    else if (ds.LineChartType == LineChartTypeEnum.Spline)
                    {
                        PointF[] pts = new PointF[ds.PointList.Count];
                        for (int i = 0; i < pts.Length; i++)
                        {
                            if (!ds.IsY2Data)
                            {
                                pts[i] = cs.Point2D((PointF)(ds.PointList[i]), xa, ya);
                            }
                            else
                            {
                                pts[i] = cs.Point2DY2((PointF)(ds.PointList[i]), xa, y2a);
                            }
                        }
                        g.DrawCurve(aPen, pts);
                    }
                    #endregion
                    #region Stairstep
                    // Plot Stairstep:
                    else if (ds.LineChartType == LineChartTypeEnum.StairStep)
                    {
                        ArrayList aList = new ArrayList();
                        if (!ds.IsY2Data)
                        {
                            // Create Stairstep data:
                            for (int i = 0; i < ds.PointList.Count - 1; i++)
                            {
                                pt  = (PointF)ds.PointList[i];
                                pt0 = (PointF)ds.PointList[i + 1];
                                aList.Add(pt);
                                aList.Add(new PointF(pt0.X, pt.Y));
                            }
                            aList.Add(ds.PointList[ds.PointList.Count - 1]);
                            // Draw stairstep chart:
                            for (int i = 1; i < aList.Count; i++)
                            {
                                g.DrawLine(aPen, cs.Point2D((PointF)aList[i - 1], xa, ya),
                                           cs.Point2D((PointF)aList[i], xa, ya));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < ds.PointList.Count - 1; i++)
                            {
                                pt  = (PointF)ds.PointList[i];
                                pt0 = (PointF)ds.PointList[i + 1];
                                aList.Add(pt);
                                aList.Add(new PointF(pt0.X, pt.Y));
                            }
                            aList.Add(ds.PointList[ds.PointList.Count - 1]);
                            for (int i = 1; i < aList.Count; i++)
                            {
                                g.DrawLine(aPen, cs.Point2DY2((PointF)aList[i - 1], xa, y2a),
                                           cs.Point2DY2((PointF)aList[i], xa, y2a));
                            }
                        }
                    }
                    #endregion
                    #region Stem
                    // Plot Stems:
                    else if (ds.LineChartType == LineChartTypeEnum.Stem)
                    {
                        if (!ds.IsY2Data)
                        {
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                pt  = (PointF)ds.PointList[i];
                                pt0 = new PointF(pt.X, 0);
                                g.DrawLine(aPen, cs.Point2D(pt0, xa, ya), cs.Point2D(pt, xa, ya));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < ds.PointList.Count; i++)
                            {
                                pt  = (PointF)ds.PointList[i];
                                pt0 = new PointF(pt.X, 0);
                                g.DrawLine(aPen, cs.Point2DY2(pt0, xa, y2a), cs.Point2DY2(pt, xa, y2a));
                            }
                        }
                    }
                    #endregion
                    #region ErrorBar
                    //Plot ErrorBar
                    else if (ds.LineChartType == LineChartTypeEnum.ErrorBar)
                    {
                        Pen errorPen = new Pen(ds.ErrorLineStyle.LineColor, ds.ErrorLineStyle.LineThickness);
                        errorPen.DashStyle = ds.ErrorLineStyle.LinePattern;
                        float barLength = 0;

                        if (!ds.IsY2Data)
                        {
                            // Draw lines:
                            for (int i = 1; i < ds.PointList.Count; i++)
                            {
                                pt0 = (PointF)ds.PointList[i - 1];
                                pt  = (PointF)ds.PointList[i];
                                g.DrawLine(aPen, cs.Point2D(pt0, xa, ya), cs.Point2D(pt, xa, ya));
                                barLength = (pt.X - pt0.X) / 4;
                            }
                            // Draw error lines:
                            for (int i = 0; i < ds.ErrorList.Count; i++)
                            {
                                PointF errorPoint = (PointF)ds.ErrorList[i];
                                PointF linePoint  = (PointF)ds.PointList[i];
                                pt0 = new PointF(linePoint.X, linePoint.Y - errorPoint.Y / 2);
                                pt  = new PointF(linePoint.X, linePoint.Y + errorPoint.Y / 2);
                                g.DrawLine(errorPen, cs.Point2D(pt0, xa, ya), cs.Point2D(pt, xa, ya));
                                PointF pt1 = new PointF(pt0.X - barLength / 2, pt0.Y);
                                PointF pt2 = new PointF(pt0.X + barLength / 2, pt0.Y);
                                g.DrawLine(errorPen, cs.Point2D(pt1, xa, ya), cs.Point2D(pt2, xa, ya));
                                pt1 = new PointF(pt.X - barLength / 2, pt.Y);
                                pt2 = new PointF(pt.X + barLength / 2, pt.Y);
                                g.DrawLine(errorPen, cs.Point2D(pt1, xa, ya), cs.Point2D(pt2, xa, ya));
                            }
                        }
                        else
                        {
                            for (int i = 1; i < ds.PointList.Count; i++)
                            {
                                pt0 = (PointF)ds.PointList[i - 1];
                                pt  = (PointF)ds.PointList[i];
                                g.DrawLine(aPen, cs.Point2DY2(pt0, xa, y2a), cs.Point2DY2(pt, xa, y2a));
                                barLength = (pt.X - pt0.X) / 4;
                            }

                            for (int i = 0; i < ds.ErrorList.Count; i++)
                            {
                                PointF errorPoint = (PointF)ds.ErrorList[i];
                                PointF linePoint  = (PointF)ds.PointList[i];
                                pt0 = new PointF(linePoint.X, linePoint.Y - errorPoint.Y / 2);
                                pt  = new PointF(linePoint.X, linePoint.Y + errorPoint.Y / 2);
                                g.DrawLine(errorPen, cs.Point2DY2(pt0, xa, y2a), cs.Point2DY2(pt, xa, y2a));
                                PointF pt1 = new PointF(pt0.X - barLength / 2, pt0.Y);
                                PointF pt2 = new PointF(pt0.X + barLength / 2, pt0.Y);
                                g.DrawLine(errorPen, cs.Point2DY2(pt1, xa, y2a), cs.Point2DY2(pt2, xa, y2a));
                                pt1 = new PointF(pt.X - barLength / 2, pt.Y);
                                pt2 = new PointF(pt.X + barLength / 2, pt.Y);
                                g.DrawLine(errorPen, cs.Point2DY2(pt1, xa, y2a), cs.Point2DY2(pt2, xa, y2a));
                            }
                        }
                        errorPen.Dispose();
                    }
                    #endregion
                    #region Stock
                    else if ((ds.LineChartType == LineChartTypeEnum.HiLo || ds.LineChartType == LineChartTypeEnum.HiLoOpenClose || ds.LineChartType == LineChartTypeEnum.Candle) && ds.DataString != null)
                    {
                        SolidBrush aBrush     = new SolidBrush(ds.LineStyle.LineColor);
                        SolidBrush whiteBrush = new SolidBrush(Color.White);
                        float      barLength  = cs.PlotArea.Width / (5 * ds.DataString.GetLength(1));
                        for (int i = 0; i < ds.DataString.GetLength(1); i++)
                        {
                            float[] stockdata = new float[4];
                            for (int j = 0; j < stockdata.Length; j++)
                            {
                                stockdata[j] = Convert.ToSingle(ds.DataString[j + 1, i]);
                            }
                            PointF ptHigh, ptLow, ptOpen, ptCLose;
                            if (!ds.IsY2Data)
                            {
                                ptHigh  = cs.Point2D(new PointF(i, stockdata[1]), xa, ya);
                                ptLow   = cs.Point2D(new PointF(i, stockdata[2]), xa, ya);
                                ptOpen  = cs.Point2D(new PointF(i, stockdata[0]), xa, ya);
                                ptCLose = cs.Point2D(new PointF(i, stockdata[3]), xa, ya);
                            }
                            else
                            {
                                ptHigh  = cs.Point2DY2(new PointF(i, stockdata[1]), xa, y2a);
                                ptLow   = cs.Point2DY2(new PointF(i, stockdata[2]), xa, y2a);
                                ptOpen  = cs.Point2DY2(new PointF(i, stockdata[0]), xa, y2a);
                                ptCLose = cs.Point2DY2(new PointF(i, stockdata[3]), xa, y2a);
                            }
                            PointF ptOpen1  = new PointF(ptOpen.X - barLength, ptOpen.Y);
                            PointF ptClose1 = new PointF(ptCLose.X + barLength, ptCLose.Y);
                            PointF ptOpen2  = new PointF(ptOpen.X + barLength, ptOpen.Y);
                            PointF ptClose2 = new PointF(ptCLose.X - barLength, ptCLose.Y);


                            // Draw Hi-Lo stock chart:
                            if (ds.LineChartType == LineChartTypeEnum.HiLo)
                            {
                                g.DrawLine(aPen, ptHigh, ptLow);
                            }

                            // Draw Hi-Li-Open-Close chart:
                            else if (ds.LineChartType == LineChartTypeEnum.HiLoOpenClose)
                            {
                                g.DrawLine(aPen, ptHigh, ptLow);
                                g.DrawLine(aPen, ptOpen, ptOpen1);
                                g.DrawLine(aPen, ptCLose, ptClose1);
                            }

                            // Draw candle chart:
                            else if (ds.LineChartType == LineChartTypeEnum.Candle)
                            {
                                PointF[] pts = new PointF[4];
                                pts[0] = ptOpen1;
                                pts[1] = ptOpen2;
                                pts[2] = ptClose1;
                                pts[3] = ptClose2;
                                g.DrawLine(aPen, ptHigh, ptLow);
                                if (stockdata[0] > stockdata[3])
                                {
                                    g.FillPolygon(aBrush, pts);
                                }
                                else if (stockdata[0] < stockdata[3])
                                {
                                    g.FillPolygon(whiteBrush, pts);
                                }
                                g.DrawPolygon(aPen, pts);
                            }
                        }
                        aBrush.Dispose();
                        whiteBrush.Dispose();
                    }
                    #endregion
                    aPen.Dispose();
                }
            }


            // Plot Symbols:
            foreach (DataSeries ds in dc.DataSeriesList)
            {
                if (ds.LineChartType != LineChartTypeEnum.HiLo && ds.LineChartType != LineChartTypeEnum.HiLoOpenClose && ds.LineChartType != LineChartTypeEnum.Candle)
                {
                    for (int i = 0; i < ds.PointList.Count; i++)
                    {
                        PointF pt = (PointF)ds.PointList[i];
                        if (!ds.IsY2Data)
                        {
                            if (pt.X >= xa.XLimMin && pt.X <= xa.XLimMax &&
                                pt.Y >= ya.YLimMin && pt.Y <= ya.YLimMax)
                            {
                                ds.SymbolStyle.DrawSymbol(g, cs.Point2D((PointF)ds.PointList[i], xa, ya));
                            }
                        }
                        else
                        {
                            if (pt.X >= xa.XLimMin && pt.X <= xa.XLimMax &&
                                pt.Y >= y2a.Y2LimMin && pt.Y <= y2a.Y2LimMax)
                            {
                                ds.SymbolStyle.DrawSymbol(g, cs.Point2DY2((PointF)ds.PointList[i], xa, y2a));
                            }
                        }
                    }
                }
            }
        }