Plotting a 2D Array into a chart control as a polynomial, VB 2010
(VB 2010 Express)
Hi all,
So I have a 2D array of data, specifically, one "Cv" value for every 10% increment. I have been able to get the Cv's plotted vs % open with the following method:
Code:
Private Sub btnPlot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlot.Click
Dim tempString As String
Dim tempByte As Byte
Dim i As Byte = 1
tempString = listValveSuggestions.SelectedItem
tempByte = CByte(tempString.Split(", ")(1))
MsgBox(tempString & vbCrLf & tempByte, , "Plotting")
Dim dTest As New DataTable
dTest.Columns.Add("% Open", GetType(Byte))
dTest.Columns.Add("Cv", GetType(Decimal))
dTest.Rows.Add(0, 0)
dTest.Rows.Add(10, CvArray(tempByte, 10))
dTest.Rows.Add(20, CvArray(tempByte, 9))
dTest.Rows.Add(30, CvArray(tempByte, 8))
dTest.Rows.Add(40, CvArray(tempByte, 7))
dTest.Rows.Add(50, CvArray(tempByte, 6))
dTest.Rows.Add(60, CvArray(tempByte, 5))
dTest.Rows.Add(70, CvArray(tempByte, 4))
dTest.Rows.Add(80, CvArray(tempByte, 3))
dTest.Rows.Add(90, CvArray(tempByte, 2))
dTest.Rows.Add(100, CvArray(tempByte, 1))
With CvVSPercentOpen.ChartAreas(0)
.AxisX.Minimum = 0
.AxisX.Maximum = 100
.AxisY.Minimum = 0
.AxisY.Maximum = CvArray(tempByte, 1)
.AxisY.Interval = 10 ' for now
.AxisX.Title = "% Open"
.AxisY.Title = "Cv"
End With
With CvVSPercentOpen.Series(0)
.Points.DataBind(dTest.DefaultView, "% Open", "Cv", Nothing)
.ChartType = DataVisualization.Charting.SeriesChartType.Spline '<--- I'd like to change this, but there is no polynomial option
.BorderWidth = 2
End With
End Sub
Which produces the attached graph. I need this code to be able to produce a smooth curve of best fit like Excel would.
Part 2
I haven't yet looked into this, but if there's any way to also export this graph as an image into an excel spreadsheet, I would also appreciate code related to that. We will be creating several spec sheets as excel workbooks and we will need to be outputting standardized sheets, which is why I'm trying to make this an application instead of directly implementing the code in Excel with VBA.