I am adding a trendline to my chart in C# via a series collection. I have a dropdown box and so each time a new chart is selected I want it to make the new chart with the new trendline. The problem is I can't seem to get the if statement to work correctly....it never seems to detect the Series "TrendLine" if it exists in the if statement. It will add the trendline the first chart I make but then it says "Trendline already exists" as an error. I have tried the if statement in the below code but it never gets to the else.
private void trendline()
{
//this.lineGraph.Series.Remove(this.lineGraph.Series["TrendLine"]);
if (this.lineGraph.Series.IndexOf("TrendLine") < 0)
{
this.lineGraph.Series.Add("Trendline");
}
else
{
this.lineGraph.Series["TrendLine"].Points.Clear();
}
this.lineGraph.Series["Trendline"].IsVisibleInLegend = false;
this.lineGraph.Series["Trendline"].ChartType = SeriesChartType.Line;
this.lineGraph.Series["Trendline"].BorderWidth = 2;
this.lineGraph.Series["Trendline"].Color = Color.Black;
//line of best fit is linear
string typeRegression = "Linear";
//The number of days for Forecasting
string forecasting = "1";
//Show Error as a range chart
string error = "false";
//Show forecasting error as a range chart
string forecastingError = "false";
//Formula parameters
string parameters = typeRegression + ',' + forecasting + ',' + error + ',' + forecastingError;
this.lineGraph.Series[0].Sort(PointSortOrder.Ascending, "X");
// Create Forecasting Series
this.lineGraph.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, parameters, this.lineGraph.Series[0], this.lineGraph.Series["Trendline"]);
}
All I want to do is to essentially either clear the trendline and remake one if one already exists or create one if the trendline doesn't exist.
Aucun commentaire:
Enregistrer un commentaire