Solved

mschart data and legendtext

Posted on 2000-05-17
2
767 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

728 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