private void ApplyData(C1Chart.ChartDataSeries c1Series, ChartUnboundDataSeries series, string propertyNname) { var seriesData = propertyNname == "SeriesData"; if (seriesData || propertyNname == "X") { series.X = c1Series.X.CopyDataOut(typeof(double)) as double[]; } if (seriesData || propertyNname == "Y") { series.Y = c1Series.Y.CopyDataOut(typeof(double)) as double[]; } if (seriesData || propertyNname == "Y1") { series.Y1 = c1Series.Y1.CopyDataOut(typeof(double)) as double[]; } if (seriesData || propertyNname == "Y2") { series.Y2 = c1Series.Y2.CopyDataOut(typeof(double)) as double[]; } if (seriesData || propertyNname == "Y3") { series.Y3 = c1Series.Y3.CopyDataOut(typeof(double)) as double[]; } }
/// <summary> /// 表达式计算 /// </summary> /// <param name="text"></param> /// <param name="txtLabel"></param> /// <param name="pf"></param> void AddNewFunction(string text, string txtLabel, PointF[] pf) { C1.Win.C1Chart.ChartDataSeries s = new C1.Win.C1Chart.ChartDataSeries(); c1Chart1.ChartGroups.Group0.ChartData.SeriesList.Add(s); PointF[] pts = Engine.Run(text, pf); s.PointData.CopyDataIn(pts); s.Label = txtLabel + "回归"; s.Tag = txtLabel; s.FitType = FitTypeEnum.Spline; }
/// <summary> /// 多项式函数加速度 /// </summary> /// <param name="dk"></param> /// <param name="txtLabel"></param> /// <param name="pf"></param> private void FunctionPointA(double[] dk, string txtLabel, PointF[] pf) { C1.Win.C1Chart.ChartDataSeries s = new C1.Win.C1Chart.ChartDataSeries(); c1Chart1.ChartGroups.Group0.ChartData.SeriesList.Add(s); PointF[] data = (PointF[])Array.CreateInstance(typeof(PointF), pf.Length); double tempY = 0; for (int i = 0; i < pf.Length; i++) { data[i].X = pf[i].X; tempY = 2 * dk[2] + 3 * 2 * dk[3] * data[i].X + 4 * 3 * dk[4] * data[i].X * data[i].X + 5 * 4 * dk[5] * data[i].X * data[i].X * data[i].X + 6 * 5 * dk[6] * data[i].X * data[i].X * data[i].X * data[i].X; data[i].Y = (float)tempY; } s.PointData.CopyDataIn(data); s.Label = txtLabel + "回归"; s.Tag = txtLabel; s.FitType = FitTypeEnum.Spline; }
/// <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; }