Anyhow you could set a global boolean variable that if set to True causes the Charts Paint event to draw a line on the Chart once the Chart is refreshed. The y axes and x axes offsets to use which I do not know what those are. Therefore you could use the Paint event to draw a line on the Chart Control as long as you knew However the Chart drawing displayed in the Chart Control displays points to some offset of the actual y or x axes. There's a couple ways that could be performed once you have the begin and end points for the trendline you want to display.įirst the Chart Control has a Paint event. This looks like a valid TrendLine to me in the bottom pic in the image. If CheckBox1.CheckState = CheckState.Checked ThenĮlseIf CheckBox1.CheckState = CheckState.Unchecked Then Private Sub Display_series_trend_line_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged 'Show Forecasting Error as a range chart.ĭim parameters As String = Convert.ToString((Convert.ToString((Convert.ToString(typeRegression & Convert.ToString(","c)) & forecasting) & ","c) & ErrorBoolean) & ","c) & forecastingErrorĬhart1.Series("SomePoints").Sort(PointSortOrder.Ascending, "X")Ĭ(FinancialFormula.Forecasting, "Linear,1,false,false", Chart1.Series("SomePoints"), Chart1.Series("TrendLine"))ĭim DisplaySeriesTrendLine As Boolean = False Me.Location = New Point(CInt(( / 2) - (Me.Width / 2)), CInt(( / 2) - (Me.Height / 2)))Ĭhart1.ChartAreas(0). = FalseĬhart1.Series("SomePoints").ChartType = SeriesChartType.PointĬhart1.Series("SomePoints").MarkerStyle = MarkerStyle.Star10Ĭhart1.Series("SomePoints").MarkerSize = 16Ĭhart1.Series("SomePoints").MarkerColor = Color.OrangeRedĬhart1.Series("SomePoints").MarkerBorderWidth = 2Ĭhart1.Series("SomePoints").MarkerBorderColor = Color.LimeĬhart1.Series("SomePoints").IsVisibleInLegend = FalseĬhart1.Series("SomePoints").Points.AddXY(CDbl(i), CDbl(Rand.Next(CInt(i / 2), CInt((i / 2) + 20)))) Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Imports .Chartingĭim TrendLine As New .Charting.Series("TrendLine") I suppose represent what the string commands do maybe.Īnd I didn't spend any time at the link for DataManipulator trying to figure anything out.
I hope you can figure out how to alter the string commands used with it ("Linear,1,false,false") which the code originator used but also had variables with names set to those values but didn't use the variables which is O.K.
Then of course the CheckBox can add/remove it from the Charts Series and it contains TrendLine points or however that works. Then the "TrendLine" series can be removed from the Charts
However the "TrendLine" series is required to be added as a Series to the Charts Series prior to using the DataManipulator. How to draw trendline using charting controlĪnyhow to use the DataManipulator the code below works. I used code from second link, altered commented out areas in Notepad from apostrophes to // like C# uses and used Wallah I found two links concerning usingĭataManipulator Class which of course is poorly documented unless I suppose you find it and understand the concepts of it from the drivel provided by Microsoft. I didn't check any links in the page but doubt any code examples are forthcoming. Anyhow I then decided to research about TrendLine for Chart Control which I've done in the past. Jacky.W provided which is for use with Excel I suppose. I can't see any built-in facility to add a trendline to an existing series like there is in Excel.Ĭan anyone advise me, or point to any examples on how this can be done pragmatically with Martin C 007
I was hoping to be able to add a checkbox item that allows a linear trend line to be displayed/hidden on the chart at runtime. This is the chart setup = CFChartTableSortedĭim Series1 As = ("WeekEnding")į(Series1.Name).XValueMember = "WeekEnding"į(Series1.Name).YValueMembers = "Balance" This is the datatable headings Dim ChartResultsTable As New DataTableĬ("DateSort", GetType(String))Ĭ("WeekEnding", GetType(String))Ĭ("Balance", GetType(Double)) I have a chart that is linked to a datatable