Beispiel #1
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;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private List <OutputCurveEntity> getCurvesFromCurveDataDgv()
        {
            List <OutputCurveEntity> curveList = new List <OutputCurveEntity>();
            int curAxisCol = -1;
            Dictionary <OutputAxisEntity, PointPairList> Dic = new Dictionary <OutputAxisEntity, PointPairList>();

            for (int col = 1; col < this._curveDataDgv.Columns.Count; col++)
            {
                string axis = this._curveDataDgv["col" + col.ToString(), 0].Value != null ? this._curveDataDgv["col" + col.ToString(), 0].Value.ToString() : string.Empty;

                if (axis == EnumAxis.X.GetDescription())//遇到X轴
                {
                    #region
                    curAxisCol = col;

                    if (Dic.Count > 0)
                    {
                        OutputCurveEntity curve = new OutputCurveEntity()
                        {
                            X = this._axisItemList.Where(o => o.Axis == axis).FirstOrDefault()
                        };

                        Dictionary <OutputAxisEntity, PointPairList> tempDic = new Dictionary <OutputAxisEntity, PointPairList>();
                        foreach (var key in Dic.Keys)
                        {
                            tempDic.Add((OutputAxisEntity)key.Clone(), Dic[key]);
                        }
                        curve.Curves = tempDic;
                        curveList.Add(curve);
                        Dic.Clear();
                    }

                    continue;
                    #endregion
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(axis))
                    {
                        continue;
                    }

                    string tempName  = this._curveDataDgv["col" + col.ToString(), 1].Value != null ? this._curveDataDgv["col" + col.ToString(), 1].Value.ToString() : string.Empty;
                    string curveName = this._curveDataDgv["col" + col.ToString(), 2].Value != null ? this._curveDataDgv["col" + col.ToString(), 2].Value.ToString() : string.Empty;

                    if (string.IsNullOrWhiteSpace(tempName) || string.IsNullOrWhiteSpace(curveName))//如果有空则跳出
                    {
                        continue;
                    }

                    PointPairList list = getPointListFromDgv(curAxisCol, col);

                    OutputAxisEntity outputYAxis = (OutputAxisEntity)this._axisItemList.Where(o => o.Axis == axis).FirstOrDefault().Clone();
                    outputYAxis.CurveName = curveName;
                    if (list.Count > 0 && !string.IsNullOrWhiteSpace(curveName))
                    {
                        Dic.Add(outputYAxis, list);
                    }
                }
            }
            if (curAxisCol != -1)
            {
                string tempAxis = this._curveDataDgv["col" + curAxisCol.ToString(), 0].Value != null ? this._curveDataDgv["col" + curAxisCol.ToString(), 0].Value.ToString() : string.Empty;

                if (Dic.Count > 0)
                {
                    OutputCurveEntity curve = new OutputCurveEntity()
                    {
                        X = this._axisItemList.Where(o => o.Axis == tempAxis).FirstOrDefault()
                    };
                    Dictionary <OutputAxisEntity, PointPairList> tempDic = new Dictionary <OutputAxisEntity, PointPairList>();
                    foreach (var key in Dic.Keys)
                    {
                        tempDic.Add((OutputAxisEntity)key.Clone(), Dic[key]);
                    }
                    curve.Curves = tempDic;
                    curveList.Add(curve);
                    Dic.Clear();
                }
            }

            return(curveList);
        }