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
642 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now