Stacked horizontal lines

TeeChart for ActiveX, COM and ASP
Post Reply
MarkR
Newbie
Newbie
Posts: 8
Joined: Mon Dec 15, 2003 5:00 am
Location: Traverse City, MI
Contact:

Stacked horizontal lines

Post by MarkR » Thu Aug 05, 2004 3:26 am

My apologies, I must be overlooking the obvious, but I'm having trouble figuring out how to create a simple stacked horizontal bar series.

Let's say I want to create a horizontal stacked bar representing used/free space on a user's "C" drive. I'd like the first part of the bar to represent the "free" space (with a green color), and the remainder of the bar to represent the "used" space (red color).

Could I get a code example of how to do this? I'm using C++, but any language will be fine (I can translate).

And if I want to do this in a loop (for multiple drives), I would call AddSeries(scHorizBar) bar once for each iteration, correct?

- MR

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Aug 05, 2004 9:27 am

Hi,

you can use one Horiz. Bar series for each drive, and set them to SelfStack, i.e :

Code: Select all

Private Sub Form_Load()
With TChart1
    .AddSeries scHorizBar
    .Series(0).asHorizBar.MultiBar = mbSelfStack
    .Series(0).ColorEachPoint = True
    .Series(0).Add 75, "DriveC", vbGreen
    .Series(0).Add 25, "DriveC", vbRed
End With
End Sub

MarkR
Newbie
Newbie
Posts: 8
Joined: Mon Dec 15, 2003 5:00 am
Location: Traverse City, MI
Contact:

Post by MarkR » Fri Aug 06, 2004 12:51 am

Hi Josep,

Thanks very much for your prompt reply, it was very helpful. The final issue I'm having is with the labeling. If I have an array of two drives, I add each of them in a loop:

LOOP HERE:
m_Chart1.AddSeries(scHorizBar);
m_Chart1.Series(i).SetColorEachPoint(TRUE);
m_Chart1.Series(i).GetMarks().SetVisible(FALSE);
m_Chart1.Series(i).Add((double)(dwlFree / 1024), sDrive, BLUE);
m_Chart1.Series(i).Add((double)(dwUsed / 1024), sDrive, RED);
END LOOP.
m_Chart1.Series(0).GetAsHorizBar().SetMultiBar(mbSelfStack);

In this case, the sDrive variable contains the drive letter, but for some reason it doesn't change in the graph. Both bars are labeled as the first drive (even though I know the variable contains the correct value on the second loop iteration).

- MR

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Aug 06, 2004 9:12 am

Hi,
this happens because it gives only the labels of the first Series, one solution could be to set the custom axis labels in the OnGetAxisLabel event :

Code: Select all

Private Sub TChart1_OnGetAxisLabel(ByVal Axis As Long, ByVal SeriesIndex As Long, ByVal ValueIndex As Long, LabelText As String)
If Axis = 0 Then
    If ValueIndex = 0 Then
        LabelText = "C"
    Else
        LabelText = "D"
    End If
End If
End Sub

MarkR
Newbie
Newbie
Posts: 8
Joined: Mon Dec 15, 2003 5:00 am
Location: Traverse City, MI
Contact:

Post by MarkR » Sat Aug 07, 2004 3:19 am

Hi Pep,

I'm still having trouble with the lables of self-stacked horizontal bars. I added an event sink for OnGetAxisLabel as per your suggestion, but for some reason it only fires for the first couple of series. Is there another way?

I should probably mention that I'm using v6 of the ActiveX version of TeeChart.

- MR

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Aug 09, 2004 8:16 am

Hi,

yes, if you're usin the TC v6 you can add custom labels on the Axes. You can see an example which shows how to do this in the Demo Features project under :
Welcome ! -> New Features -> Chart -> Axes -> Custom Labels

Post Reply