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
Stacked horizontal lines
Hi,
you can use one Horiz. Bar series for each drive, and set them to SelfStack, i.e :
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
Pep Jorge
http://support.steema.com
http://support.steema.com
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
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
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 :
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
Pep Jorge
http://support.steema.com
http://support.steema.com
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
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
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
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
Pep Jorge
http://support.steema.com
http://support.steema.com