Please, urgent! Bar chart with self-defined x-axis?

TeeChart for ActiveX, COM and ASP
Post Reply
David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Please, urgent! Bar chart with self-defined x-axis?

Post by David » Wed Jul 12, 2006 8:20 am

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jul 12, 2006 9:31 am

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);
}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Wed Jul 12, 2006 9:58 am

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jul 12, 2006 12:04 pm

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
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Thu Jul 13, 2006 6:12 am

Solved. Thanks!

Post Reply