protected override void SetupChart() { this.flexChart1.Header.Content = "Relationship between Production and Cost"; this.flexChart1.Header.Style.Font = StyleInfo.ChartHeaderFont; this.flexChart1.DataSource = DataService.GetUnitCostData(); this.flexChart1.ChartType = ChartType.LineSymbols; this.flexChart1.BindingX = "Units"; var closePrice = new Series { Binding = "Cost", Name = "Cost", }; _trendLine = new C1.Win.Chart.TrendLine() { Name = "Trend Line", Binding = "Cost", Order = 4, FitType = FitType.Linear, }; this.flexChart1.Series.Add(closePrice); this.flexChart1.Series.Add(_trendLine); this.flexChart1.AxisX.Title = "Quantity"; this.flexChart1.AxisX.TitleStyle.Font = StyleInfo.AxisTitleFont; this.flexChart1.AxisY.Title = "Per Unit Cost"; this.flexChart1.AxisY.TitleStyle.Font = StyleInfo.AxisTitleFont; this.flexChart1.Rendered += FlexChart1_Rendered; this.flexChart1.MouseUp += (s, e) => { _clickedItem = null; }; this.flexChart1.MouseLeave += (s, e) => { _clickedItem = null; }; this.flexChart1.MouseDown += FlexChart1_MouseDown; this.flexChart1.MouseMove += FlexChart1_MouseMove; }
string GetEquationString(C1.Win.Chart.TrendLine trendLine) { string result = String.Empty; int X = 1, Y0 = 0; switch (trendLine.FitType) { case FitType.Linear: result = String.Format("y={1:0.0000}x{0:+0.0000;-0.0000;+0}", trendLine.Coefficients[0], trendLine.Coefficients[1]); break; case FitType.Exponent: result = String.Format("y={0:0.0000}e<sup>{1:0.0000}x</sup>", trendLine.Coefficients[0], trendLine.Coefficients[1]); break; case FitType.Logarithmic: result = String.Format("y={1:0.0000}ln(x){0:+0.0000;-0.0000;+0}", trendLine.Coefficients[0], trendLine.Coefficients[1]); break; case FitType.Power: result = String.Format("y={0:0.0000}x<sup>{1:0.0000}</sup>", trendLine.Coefficients[0], trendLine.Coefficients[1]); break; case FitType.Polynom: result = String.Format("{1:+0.0000;-0.0000;+0}x{0:+0.0000;-0.0000;+0}", trendLine.Coefficients[0], trendLine.Coefficients[1]); for (int i = 2; i <= (int)_udOrder.Value; i++) { result = result.Insert(0, String.Format("{0:+0.000;-0.0000;+0}x<sup>{1}</sup>", trendLine.Coefficients[i], i)); } result = result.Remove(0, 1).Insert(0, "y="); break; case FitType.Fourier: result = String.Format("{0:+0.0000;-0.0000;+0}", trendLine.Coefficients[0]); for (int i = 2, a = 1; i <= (int)_udOrder.Value; i++, a = i % 2 == 0 ? a + 1 : a) { result += String.Format("{0:+0.000;-0.0000;+0}{2}({1}x)", trendLine.Coefficients[i - 1], a == 1 ? "" : a.ToString(), (i) % 2 == 0 ? "cos" : "sin"); } result = result.Remove(0, 1).Insert(0, "y="); break; case FitType.MaxX: result = "x=" + trendLine.GetValues(X).Max(); break; case FitType.MinX: result = "x=" + trendLine.GetValues(X).Min(); break; case FitType.MaxY: result = "y=" + trendLine.GetValues(Y0).Max(); break; case FitType.MinY: result = "y=" + trendLine.GetValues(Y0).Min(); break; case FitType.AverageX: result = "x=" + trendLine.GetValues(X).Average(); break; case FitType.AverageY: result = "y=" + trendLine.GetValues(Y0).Average(); break; } return(result); }