Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
699 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Assisted Solution

by:Leo Eikelman
Leo Eikelman earned 900 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 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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