?
Solved

mschart data and legendtext

Posted on 2000-05-17
2
Medium Priority
?
781 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
[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
2 Comments
 
LVL 1

Accepted Solution

by:
csameer1 earned 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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

719 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