Solved

mschart data and legendtext

Posted on 2000-05-17
2
740 Views
Last Modified: 2008-02-01
Hi,

I'm trying to make a 2dline chart for a report that will track archived stats based on dates and percentages. A sample of the data looks like this:

ID    #ofEvents  #ofClicks  DateArchived
1      100          10          01/01/00
1      200          20          01/02/00
2      10            1          01/01/00
2      50            2          01/02/00

I'm pulling the data from a table using ADO, and have it populating an array. This charts just fine, with a horizontal line for however many distinct id's i have, with the percentage (#ofclicks/#of events) being shown up the side of the chart, and the dates being shown as columns along the bottom.
My problem is, getting the 'names' for each row to show in the legend. I'm using:
MSChart.Plot.SeriesCollection(j).LegendText = 'rowName' in a loop to set the names. This works great for 4 or less rows, but gives me an "Index given out of bounds" error when I reach the j = 5 loop. I'm not sure how MSChart determines how many series there are, so I can't figure where or how to set this.
I've tried using the mschart.row = 1, mschart.rowlabel = "name" method, but while the labels are properly set to the names, they don't show in the legend.
If anyone knows how to manipulate the series collection, that'd be the easiest way, but if I'm way off track, please let me know an easier way =)

Thanks a million in advance,
Geoff

Here's a shortened version of the function I'm using:

Public Function GetChart(SQL As String, startDate As Date, endDate As Date)

    Dim arrData()
    Dim itemCount As Integer
    Dim daysCount As Integer
    Dim SQLChart As String
    Dim i, j As Integer
    Dim rsChart As ADODB.Recordset
    Dim rsItemId As ADODB.Recordset
   
    Set rsChart = New ADODB.Recordset
    Set rsItemId = New ADODB.Recordset

    Call OpenConn    'opens adodb.connection

    rsItemId.Open SQL, myConnection, adOpenStatic, adLockOptimistic, adCmdText

    daysCount = DateDiff("d", startDate, endDate)

    rsItemId.MoveLast
    itemCount = rsItemId.RecordCount
       
    j = 1

    ReDim arrData(0 To (daysCount - 1), 0 To itemCount)
   
    rsItemId.MoveFirst
    Do Until rsItemId.EOF

        CampItemId = rsItemId(0)

        SQLChart = "SELECT campaign_item_id,events_served, clicks_served, date_archived FROM as_performance_archive WHERE " & _
            "date_archived BETWEEN " & Chr(39) & CDate(startDate) & Chr(39) & " AND " & Chr(39) & CDate(endDate) & Chr(39) & _
            " AND campaign_item_id = " & CampItemId & " ORDER BY campaign_item_id, date_archived"

        rsChart.Open SQLChart, myConnection, adOpenStatic, adLockOptimistic, adCmdText

        rsChart.MoveFirst

        For i = 0 To daysCount - 1
            arrData(i, 0) = rsChart(3)
            arrData(i, j) = (rsChart(2) / rsChart(1)) * 100
            rsChart.MoveNext
        Next i
        frmChart.MSChart.Plot.SeriesCollection(j).LegendText = GetAdName(CampItemId)
        'GetAdName is another function to pull the name
        j = j + 1

        rsItemId.MoveNext
        rsChart.Close

    Loop

    rsItemId.Close

    With frmChart.MSChart
        .ChartData = arrData
        .ShowLegend = True
        .TitleText = "Click Rates from " & startDate & " to " & endDate
        .Legend.Location.LocationType = VtChLocationTypeBottom
    End With
   
Call CloseConn
   
    Set rsChart = Nothing
    Set rsItemId = Nothing

End Function
0
Comment
Question by:geoffgillespie
2 Comments
 
LVL 1

Accepted Solution

by:
csameer1 earned 100 total points
ID: 2832049
i am sorry,i don't use mschart any more.

I use TeeChart ,it isone of the best and easy charting controls i have ever seen,make sure you try it.http://www.teemach.com
0
 

Author Comment

by:geoffgillespie
ID: 2833863
thanks, i'll check it out
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

777 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