Solved

MSchart control: Source data is from a text file. And then use the MSchart to represent the data distribution.

Posted on 2006-04-03
3
656 Views
Last Modified: 2012-06-27
Hi
I have a text file with 2 columns and about 2000 rows of value. It looks like below

col_1 col_2
709.0 1220.0
391.0 1181.0
295.0 303.0
289.0 1303.0
2714.0 303.0
2745.0 1303.0
261.0 1254.0
And so on…

I want to use MS chart control to draw a chart. The chart shows the 2 column's values in 2 different colors. The chart doesn't need to be too fancy and complicated (just need show the chart after load the form). And
because there so many rows of data in the text file. Can ms chart control adjust the scale to let the chart looks not too crowded (just need manual change the in coding place)?
0
Comment
Question by:hsuyf
3 Comments
 
LVL 8

Assisted Solution

by:Leo Eikelman
Leo Eikelman earned 300 total points
ID: 16364233
I found this code example

-------------------------------------------------

Private Values() As Single
Private NumPoints As Integer
Private NumYs As Integer

Private Sub LoadData()
Dim fnum As Integer
Dim fname As String
Dim pt_num As Integer
Dim val_num As Integer
Dim X As Single

    ' Open the file.
    fnum = FreeFile
    fname = App.Path
    If Right$(fname, 1) <> "\" Then fname = fname & "\"
    fname = fname & "points.dat"
    Open fname For Input As #fnum

    ' Read the number of values.
    Input #fnum, NumPoints, NumYs
    ReDim Values(1 To NumPoints, 1 To 2 * NumYs)

    ' Read the data.
    For pt_num = 1 To NumPoints
        Input #fnum, X
        For val_num = 0 To NumYs - 1
            Values(pt_num, 2 * val_num + 1) = X
            Input #fnum, Values(pt_num, 2 * val_num + 2)
        Next val_num
    Next pt_num
   
    Close #fnum
End Sub
 
 
 
After loading the data, the program uses the following code to send the data to the MSChart control. It uses the VtChChartType2dXY chart type to give each data set its own X and Y values.
 
 
 
' Send the data to the chart.
Chart1.chartType = VtChChartType2dXY
Chart1.RowCount = NumPoints
Chart1.ColumnCount = 2 * NumYs
Chart1.ChartData = Values
 

-----------------------------------------------------------------------

you can find the source and app here

http://www.vb-helper.com/howto_mschart_graph_file_data.html


This tutorial might help as well

http://www.4guysfromrolla.com/webtech/MSChartExample.shtml


Cheers,

Leo
0
 

Author Comment

by:hsuyf
ID: 16366383
I found this example. but i still have problem to implement my project. Could you help me more about my example?

thanks
0
 
LVL 2

Accepted Solution

by:
LSORRELLS earned 200 total points
ID: 16402969
Try this ...
After the file is imported

Cells(1,1). Activate ' puts you in the upper most cell where the col header is
MyRange = ActiveCell.CurrentRegion.Address ' Creates a range Address  bordered by empty col and rows
Charts(1).Seriescollection.Add Source = ActiveWorksheet.Range(MyRAnge) 'Creates the Chart

'After the chart is created'

Charts(1).Activate ' makes the new chart Active
With ActiveChart
      .Charttype = XLLine  'makes sure you have a line chart (you can use whatever you want e.g. xlbar...)
      .Axes(xlcategory).majorunitisAuto = True
Endwith

You can add other modifications (titiles etc within the with object to automate changes to your chart.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

914 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

18 Experts available now in Live!

Get 1:1 Help Now