string CreateStatisticsString(RegressionStatistics rs, string fmt, bool coeffs) { string s = "Statistics\n----------\n"; if (coeffs) { double[] k = rs.Coeffs; for (int i = 0; i < k.Length; i++) { s += string.Format("k[{0}]\t= {1}\n", i, k[i].ToString(fmt)); } } s += string.Format( "RSQ\t= {0}\nSEY\t= {1}\nF\t= {2}\nDF\t= {3}\nSSR\t= {4}\nSSE\t= {5}", rs.Rsq.ToString(fmt), rs.Sey.ToString(fmt), rs.F.ToString(fmt), rs.DF.ToString(fmt), rs.Ssr.ToString(fmt), rs.Sse.ToString(fmt)); return(s); }
private void UpdateStatisticsLabel() { C1.Win.C1Chart.Label lbl; if (c1Chart1.ChartLabels.LabelsCollection.Count < 1) { // create statistics label lbl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel(); lbl.AttachMethod = AttachMethodEnum.Coordinate; lbl.Style.BackColor = Color.FromArgb(192, Color.MistyRose); lbl.Style.GradientStyle = GradientStyleEnum.None; lbl.Style.Border.BorderStyle = BorderStyleEnum.Solid; lbl.Style.Border.Color = Color.IndianRed; lbl.Style.Border.Rounding.All = 15; lbl.Compass = LabelCompassEnum.West; lbl.Style.VerticalAlignment = C1.Win.C1Chart.AlignVertEnum.Center; lbl.Style.Font = new Font("Lucida Console", 8); } else { lbl = c1Chart1.ChartLabels[0]; } TrendLine tl = null; if (c1Chart1.ChartGroups[0].ChartData.TrendsList.Count > 0) { tl = c1Chart1.ChartGroups[0].ChartData.TrendsList[0]; } else { return; } RegressionStatistics rs = tl.RegressionStatistics; bool isRegression = (tl.TrendLineType == TrendLineTypeEnum.Exponent) || (tl.TrendLineType == TrendLineTypeEnum.Fourier) || (tl.TrendLineType == TrendLineTypeEnum.Logarithmic) || (tl.TrendLineType == TrendLineTypeEnum.Polynom) || (tl.TrendLineType == TrendLineTypeEnum.Power); if ((rs == null) && isRegression) { lblErrorData.Visible = true; } else { lblErrorData.Visible = false; } if (rs != null && cbViewStatistics.Checked) { lbl.Text = CreateStatisticsString(rs, "g4", false); //string.Format( //"Statistics\n----------\nRSQ\t= {0:g4}\nSEY\t= {1:g4}\nF\t= {2:g4}\nDF\t= {3:g4}\nSSR\t= {4:g4}\nSSE\t= {5:g4}", //rs.Rsq, rs.Sey, rs.F, rs.DF, rs.Ssr, rs.Sse); lbl.Visible = true; } else { lbl.Visible = false; } }
private void UpdateFormulaLabel() { C1.Win.C1Chart.Label lbl; if (c1Chart1.ChartLabels.LabelsCollection.Count < 2) { // create formula label lbl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel(); lbl.AttachMethod = AttachMethodEnum.Coordinate; lbl.AttachMethodData.X = c1Chart1.ChartArea.PlotArea.Location.X + c1Chart1.ChartArea.PlotArea.Size.Width / 2; lbl.AttachMethodData.Y = c1Chart1.ChartArea.PlotArea.Location.Y + 20; lbl.Style.BackColor = Color.FromArgb(192, Color.LightBlue); lbl.Style.GradientStyle = GradientStyleEnum.None; lbl.Style.Border.BorderStyle = BorderStyleEnum.Solid; lbl.Style.Border.Color = Color.DarkBlue; lbl.Style.Border.Rounding.All = 15; lbl.Style.VerticalAlignment = AlignVertEnum.Center; lbl.Compass = LabelCompassEnum.North; } else { lbl = c1Chart1.ChartLabels[1]; } TrendLine tl = null; if (c1Chart1.ChartGroups[0].ChartData.TrendsList.Count > 0) { tl = c1Chart1.ChartGroups[0].ChartData.TrendsList[0]; } else { return; } RegressionStatistics rs = tl.RegressionStatistics; if (rs == null || rs.Coeffs == null || !cbViewFormula.Checked) { lbl.Visible = false; return; } TrendLineTypeEnum tlt = (TrendLineTypeEnum)cbTrendType.SelectedItem; string s_regr = GetFormula(tlt, rs.Coeffs); string s_exact = GetFormula(dtLastGenerated, k); if (s_regr.Length > 0 && s_exact.Length > 0) { lbl.Visible = true; lbl.Text = string.Format("Data formula: {0}\n\nRegression formula: {1}", s_exact, s_regr); } else if (s_regr.Length > 0) { lbl.Visible = true; lbl.Text = string.Format("Regression formula: {1}", s_exact, s_regr); } else { lbl.Visible = false; } }