Custom Charting in VB express

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...
VBlearner100Asked:
Who is Participating?
 
Robert SchuttConnect With a Mentor Software EngineerCommented:
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
        Try
            Using da As New OdbcDataAdapter("select * from [data.csv]", "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & C_DATADIR & ";Extensions=csv;")
                da.Fill(dt)
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        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)
        Next
    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:
[data.csv]
ColNameHeader=False
Format=CSVDelimited
MaxScanRows=1
CharacterSet=ANSI

Open in new window

example data.csv:
1,10,15,20,5
2,15,30,10,5
3,10,15,10,5
4,15,5,10,5

Open in new window

example output:example output capture
0
 
VBlearner100Author Commented:
Thank you very much and for the clear example.. this is very insightful..
0
 
Robert SchuttSoftware EngineerCommented:
Hi, any more info you need? Otherwise please close the question.

cheers,
Robert.
0
 
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.