Page 1 of 1
Please, urgent! Bar chart with self-defined x-axis?
Posted: Wed Jul 12, 2006 8:20 am
by 9529132
Hi, there,
I would like to generate a bar chart where the bar width is exactly the predefined x-axis range segments. For example, if I define some x-axis segments like [-2.5 -1.5] [-1.5 -0.5] [-0.5 0.5][0.5 1.5][1.5 2.5], how can I set the bar width to be exactly the width of the x-axis range in the chart?
Thank you very much!
David
Posted: Wed Jul 12, 2006 9:31 am
by narcis
Hi David,
Yes, you can do something like this:
Code: Select all
double CCppTest2Dlg::AddBarRange(double Start, double End)
{
return (Start+((End-Start)/2));
}
void CCppTest2Dlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
m_Chart1.GetAspect().SetView3D(true);
m_Chart1.AddSeries(scBar);
m_Chart1.Series(0).GetAsBar().SetBarWidthPercent(100);
m_Chart1.Series(0).AddXY(AddBarRange(-2.5,-1.5),5,"",clTeeColor);
m_Chart1.Series(0).AddXY(AddBarRange(-1.5,-0.5),7,"",clTeeColor);
m_Chart1.Series(0).AddXY(AddBarRange(-0.5,0.5),2,"",clTeeColor);
m_Chart1.Series(0).AddXY(AddBarRange(0.5,1.5),7,"",clTeeColor);
m_Chart1.Series(0).AddXY(AddBarRange(1.5,2.5),1,"",clTeeColor);
m_Chart1.GetAxis().GetBottom().SetIncrement(0.5);
m_Chart1.GetAxis().GetBottom().GetLabels().SetSeparation(0);
}
Posted: Wed Jul 12, 2006 9:58 am
by 9529132
Hi, NarcĂs,
Yeah, it works when the chart was initially loaded. But if I zoom in, the settings won't work. In addition, if I have around 50 bars and the x increment is 0.5, the labels are all jammed together. Any suggestion?
Thank you very much!
David
Posted: Wed Jul 12, 2006 12:04 pm
by narcis
Hi David,
The zoom issue is a bug which I have added to our defect list (TV52011568) to be fixed for future releases.
Regarding the labels issue, you can set bigger label separation or not setting a label separation, leave it automatic (default behaviour).
Another option would be that you set which labels you want to display, for example something like this:
Code: Select all
Private Sub TChart1_OnGetAxisLabel(ByVal Axis As Long, ByVal SeriesIndex As Long, ByVal ValueIndex As Long, LabelText As String)
Dim val As Double
val = LabelText
If Axis = 3 Then
If (val Mod 2) = 0 Then
LabelText = " "
Else
LabelText = LabelText
End If
End If
End Sub
Posted: Thu Jul 13, 2006 6:12 am
by 9529132
Solved. Thanks!