Custom Charting in VB express

Posted on 2012-09-02
Last Modified: 2012-10-14
Hi, I am trying to use the VB charts feature to plot custom x-y plots in VB charts...
I'd like to import data from an external *.dat file  which is basically a column vector of data (x, y1, y2....yn)..
I am guessing that it has to do something with the "datasource" option in chart properties.. However, it seems to work databases only... How about data from simple files like *.dat or excel etc...

Appreciate your suggestions...
Question by:VBlearner100
    LVL 35

    Accepted Solution

    If you're willing to take a little detour, this is how it could be done with a datatable taken from a .csv file (strangely, .dat extension seems to be impossible but maybe I did something else wrong):
    Imports System.Data.Odbc
    Public Class Form1
        Const C_DATADIR As String = "c:/tmp/datadir"
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable
                Using da As New OdbcDataAdapter("select * from [data.csv]", "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & C_DATADIR & ";Extensions=csv;")
                End Using
            Catch ex As Exception
            End Try
            Me.Chart1.DataSource = dt
            Me.Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.StackedColumn
            For c As Integer = 0 To dt.Columns.Count - 2
                If c > 0 Then
                    Me.Chart1.Series.Add("Series" & (c + 1))
                    Me.Chart1.Series(c).ChartType = Me.Chart1.Series(0).ChartType
                End If
                ' fields from csv are called F1, F2, ...
                Me.Chart1.Series(c).XValueMember = "F1"
                Me.Chart1.Series(c).YValueMembers = "F" & (c + 2)
        End Sub
    End Class

    Open in new window

    This is assuming you put a datafile called data.csv in a folder "c:\tmp\datadir" together with a file called schema.ini:

    Open in new window

    example data.csv:

    Open in new window

    example output:example output capture

    Author Comment

    Thank you very much and for the clear example.. this is very insightful..
    LVL 35

    Expert Comment

    by:Robert Schutt
    Hi, any more info you need? Otherwise please close the question.

    LVL 44

    Expert Comment

    by:Martin Liss
    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now