Results 1 to 2 of 2

Thread: Plotting a 2D Array into a chart control as a polynomial, VB 2010

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2012

    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:

        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.

    Any help with this issue would be appreciated.

    Thanks in advance.
    Attached Images Attached Images  

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Searching for mendhak

    Re: Plotting a 2D Array into a chart control as a polynomial, VB 2010

    Moved To VB.NET
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width