예제 #1
0
        private void InitChart()
        {
            try
            {
                //this.colorPanel1.ColorBarValue = colors;
                //Random r = new Random();
                int seriescount = data.Amplitude.Length;

                ChartDataSeriesCollection coll   = c1Chart1.ChartGroups[0].ChartData.SeriesList;
                List <double>             lsttmp = new List <double>();
                #region testdata
                //int i = 0;
                //for (i = 0; i < seriescount; i++)
                //{
                //    lstdata.Add(r.Next(300, 800));
                //}
                NoiseParmBLL NoiseParmbll   = new NoiseParmBLL();
                string       str_DCLen      = NoiseParmbll.GetParm(ConstValue.DCComponentLen); //获取设定的直流分量长度
                int          DCComponentLen = 6;
                if (!string.IsNullOrEmpty(str_DCLen))
                {
                    DCComponentLen = Convert.ToInt32(str_DCLen);
                }

                float min      = DCComponentLen * 2000 / 256;
                float max      = 1000;
                float interval = (max - min) / 4;
                for (int i = 0; i < seriescount; i++)
                {
                    lsttmp = new List <double>();
                    lsttmp.Add(data.Amplitude[i]);
                    lsttmp.Add(1);
                    c1Chart1.ChartGroups[0].ChartData.SeriesList[i].Y.CopyDataIn(lsttmp.ToArray());
                    c1Chart1.ChartGroups[0].ChartData.SeriesList[i].FillStyle.Color1 = GetColor(min, max, data.Frequency[i]);
                }
                #endregion
                while (coll.Count > seriescount)
                {
                    c1Chart1.ChartGroups[0].ChartData.SeriesList.RemoveAt(seriescount);  //将多余的Series移除,总计35个
                }

                colorPanel_static1.SetColorPanel((int)Math.Ceiling(min), (int)Math.Ceiling(min + interval), (int)Math.Ceiling(min + interval * 2),
                                                 (int)Math.Ceiling(min + interval * 3), (int)Math.Ceiling(max)); //set colorpanel mark
                C1.Win.C1Chart.Axis axisX = (C1.Win.C1Chart.Axis)c1Chart1.ChartArea.AxisX;
                if (seriescount > 1)
                {
                    axisX.Max = 0.1 * (30 - seriescount) + 1.71;
                }
                else
                {
                    axisX.Max = 15;
                }

                c1Chart1.ChartArea.AxisY.ValueLabels.Add(Recorder.LeakValue, "");
                c1Chart1.ChartArea.AxisY.ValueLabels[0].Appearance = ValueLabelAppearanceEnum.TriangleMarker;
                c1Chart1.ChartArea.AxisY.ValueLabels[0].GridLine   = false;
                c1Chart1.ChartArea.AxisY.ValueLabels[0].Color      = Color.Red;
                c1Chart1.ChartArea.AxisY.ValueLabels[0].Moveable   = false;
                c1Chart1.ChartArea.AxisY.AnnoMethod = AnnotationMethodEnum.Mixed;

                c1Chart1.ChartArea.AxisY.Max     = 100;
                c1Chart1.ChartArea.AxisY.AutoMax = false;
            }
            catch (Exception ex)
            {
                logger.ErrorException("InitChart", ex);
                XtraMessageBox.Show("加载图表发生错误!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        /// <summary>
        /// Initialize the Chart in code
        /// </summary>
        private void InitChart()
        {
            groupBox1.Anchor     = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; //!!VBPassThru
            groupBox2.Anchor     = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;                      //!!VBPassThru
            chartCpuUsage.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; //!!VBPassThru
            button1.Anchor       = AnchorStyles.Bottom | AnchorStyles.Right;                                        //!!VBPassThru

            //--Initalize the Cpu Usage Chart-----------------------------
            chartCpuUsage.BackColor = Color.Black;

            C1.Win.C1Chart.PlotArea pa = chartCpuUsage.ChartArea.PlotArea;
            pa.BackColor  = Color.Black;
            pa.BackColor2 = Color.Green;
            pa.HatchStyle = C1.Win.C1Chart.HatchStyleEnum.DarkHorizontal;

            // Set up the X/Y axis
            C1.Win.C1Chart.Axis xa = chartCpuUsage.ChartArea.AxisX;
            xa.AutoMax    = false;
            xa.AutoMin    = false;
            xa.AutoMajor  = false;
            xa.AutoMinor  = false;
            xa.Min        = 0;
            xa.Max        = 100;
            xa.TickLabels = C1.Win.C1Chart.TickLabelsEnum.None;
            xa.Thickness  = 1;
            xa.ForeColor  = Color.Black;

            C1.Win.C1Chart.Axis ya = chartCpuUsage.ChartArea.AxisY;
            ya.AutoMax    = false;
            ya.AutoMin    = false;
            ya.AutoMajor  = false;
            ya.AutoMinor  = false;
            ya.Min        = 0;
            ya.Max        = 100;
            ya.TickLabels = C1.Win.C1Chart.TickLabelsEnum.None;
            ya.TickMajor  = C1.Win.C1Chart.TickMarksEnum.None;
            ya.TickMinor  = C1.Win.C1Chart.TickMarksEnum.None;
            ya.Thickness  = 1;
            ya.ForeColor  = Color.Black;
            ya.Compass    = C1.Win.C1Chart.CompassEnum.East;

            // Add a alarm zone
            C1.Win.C1Chart.AlarmZone almZone = chartCpuUsage.ChartArea.PlotArea.AlarmZones.AddNewZone();
            almZone.BackColor      = Color.Transparent;
            almZone.ForeColor      = Color.Lime;
            almZone.PatternStyle   = System.Drawing.Drawing2D.HatchStyle.DarkHorizontal;
            almZone.PatternVisible = true;
            almZone.LowerExtent    = 0;
            almZone.FarExtent      = 100;
            almZone.NearExtent     = -100;
            almZone.UpperExtent    = 0;
            almZone.Visible        = true;

            // Hide the header and legend
            chartCpuUsage.Header.Visible = false;
            chartCpuUsage.Legend.Visible = false;

            // Set up the footer
            chartCpuUsage.Footer.Style.ForeColor = Color.Lime;
            chartCpuUsage.Footer.Text            = "25%";
            chartCpuUsage.Footer.Visible         = true;

            // Set up the dummy data
            chartCpuUsage.ChartGroups[0].ChartData.SeriesList.RemoveAll();
            C1.Win.C1Chart.ChartDataSeries series = chartCpuUsage.ChartGroups[0].ChartData.SeriesList.AddNewSeries();
            series.PointData.Length = 1;
            series.PointData[0]     = new PointF(-1, -1);

            //--Initalize the Cpu History Chart-----------------------------
            chartCpuHistory.ChartGroups[0].ChartType = C1.Win.C1Chart.Chart2DTypeEnum.XYPlot;
            C1.Win.C1Chart.Style caStyle = chartCpuHistory.ChartArea.Style;
            caStyle.BackColor          = Color.BurlyWood;
            caStyle.Border.BorderStyle = C1.Win.C1Chart.BorderStyleEnum.Solid;
            caStyle.Border.Color       = SystemColors.AppWorkspace;
            caStyle.Border.Thickness   = 2;

            C1.Win.C1Chart.PlotArea plArea = chartCpuHistory.ChartArea.PlotArea;
            plArea.BackColor = Color.Black;
            plArea.ForeColor = Color.Green;
            plArea.Boxed     = true;

            // Set up the X Axis
            xa                     = chartCpuHistory.ChartArea.AxisX;
            xa.ForeColor           = Color.Green;
            xa.Min                 = 0;
            xa.Max                 = hits;
            xa.TickMajor           = C1.Win.C1Chart.TickMarksEnum.None;
            xa.TickMinor           = C1.Win.C1Chart.TickMarksEnum.None;
            xa.TickLabels          = C1.Win.C1Chart.TickLabelsEnum.None;
            xa.Compass             = C1.Win.C1Chart.CompassEnum.North;
            xa.AutoMax             = false;
            xa.AutoMin             = false;
            xa.AutoMajor           = false;
            xa.AutoMinor           = false;
            xa.UnitMinor           = 5;
            xa.UnitMajor           = 10;
            xa.Thickness           = 1;
            xa.GridMajor.AutoSpace = true;
            xa.GridMajor.Color     = Color.Green;
            xa.GridMajor.Pattern   = C1.Win.C1Chart.LinePatternEnum.Solid;
            xa.GridMajor.Visible   = true;
            xa.GridMinor.AutoSpace = true;
            xa.GridMinor.Color     = Color.Green;
            xa.GridMinor.Pattern   = C1.Win.C1Chart.LinePatternEnum.Solid;
            xa.GridMinor.Visible   = true;
            xa.Reversed            = !left2right;


            // Set up the Y Axis
            ya                     = chartCpuHistory.ChartArea.AxisY;
            ya.ForeColor           = Color.Green;
            ya.Min                 = 0;
            ya.Max                 = 1;
            ya.TickMajor           = C1.Win.C1Chart.TickMarksEnum.None;
            ya.TickMinor           = C1.Win.C1Chart.TickMarksEnum.None;
            ya.AutoMax             = false;
            xa.AutoMin             = false;
            xa.AutoMajor           = false;
            xa.AutoMinor           = false;
            ya.UnitMinor           = 0.05;
            ya.UnitMajor           = 0.1;
            ya.Thickness           = 1;
            ya.AnnoFormat          = C1.Win.C1Chart.FormatEnum.NumericManual;
            ya.AnnoFormatString    = "#0%";
            ya.GridMajor.AutoSpace = true;
            ya.GridMajor.Color     = Color.Green;
            ya.GridMajor.Pattern   = C1.Win.C1Chart.LinePatternEnum.Solid;
            ya.GridMajor.Visible   = true;
            ya.GridMinor.AutoSpace = true;
            ya.GridMinor.Color     = Color.Green;
            ya.GridMinor.Pattern   = C1.Win.C1Chart.LinePatternEnum.Solid;
            ya.GridMinor.Visible   = true;

            // Hide Header and Footer
            chartCpuHistory.Header.Visible = false;
            chartCpuHistory.Footer.Visible = false;

            // Initialize the series
            chartCpuHistory.ChartGroups[0].ChartData.SeriesList.RemoveAll();
            series = chartCpuHistory.ChartGroups[0].ChartData.SeriesList.AddNewSeries();
            series.SymbolStyle.Shape = C1.Win.C1Chart.SymbolShapeEnum.None;
            series.LineStyle.Color   = Color.LawnGreen;
            arrHistory = series.PointData;
        }