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
668 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

803 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