property Level.FormatLabel as String
Formats the labels based on the specified formula.

 TypeDescription 
   String A String expression that specifies the formula to format the level.  
By default, the FormatLabel property is Empty. The FormatLabel property has effect only if it is valid and not empty.  The Label property defines the label being shown in the chart. Use the FormatLabel property to customize the labels being displayed in the chart's level. The value keyword in the FormatLabel property specifies the label of the level as it is before formatting ( in string format ). The dvalue keyword, indicates the date-time expression of the element in the label being formatted. Also, you can use the ReplaceLabel property to replace a specified label.

If the Unit property is exDay for several levels ( more than 1 level ), you can display your subdivisions using the Count property, based on 0, not based on the FirstVisibleDate property. You can get this layout using the 

The screen shows in different colors  the Jun 27 as being the last Friday of June, and the Jul 25 as being the last Friday on July.

The supported binary arithmetic operators are:

The supported unary boolean operators are:

The supported binary boolean operators are:

The supported binary boolean operators, all these with the same priority 0, are :

The supported ternary operators, all these with the same priority 0, are :

"expression ? true_part : false_part"

, while it executes and returns the true_part if the expression is true, else it executes and returns the false_part. For instance, the "%0 = 1 ? 'One' : (%0 = 2 ? 'Two' : 'not found')" returns 'One' if the value is 1, 'Two' if the value is 2, and 'not found' for any other value. A n-ary equivalent operation is the case() statement, which is available in newer versions of the component.

The supported n-ary operators are (with priority 5):

"expression in (c1,c2,c3,...cn)"

, where the c1, c2, ... are constant elements. The constant elements could be numeric, date or string expressions. For instance the "value in (11,22,33,44,13)" is equivalent with "(expression = 11) or (expression = 22) or (expression = 33) or (expression = 44) or (expression = 13)". The in operator is not a time consuming as the equivalent or version is, so when you have large number of constant elements it is recommended using the in operator. Shortly, if the collection of elements has 1000 elements the in operator could take up to 8 operations in order to find if an element fits the set, else if the or statement is used, it could take up to 1000 operations to check, so by far, the in operator could save time on finding elements within a collection.

"expression switch (default,c1,c2,c3,...,cn)"

, where the c1, c2, ... are constant elements, and the default is a constant element being returned when the element is not found in the collection. The constant elements could be numeric, date or string expressions.  The equivalent syntax is "%0 = c 1 ? c 1 : ( %0 = c 2 ? c 2 : ( ... ? . : default) )". The switch operator is very similar with the in operator excepts that the first element in the switch is always returned by the statement if the element is not found,  while the returned value is the value itself instead -1. For instance, the "%0 switch ('not found',1,4,7,9,11)" gets 1, 4, 7, 9 or 11, or 'not found' for any other value. As the in operator the switch operator uses binary searches for fitting the element, so it is quicker that iif (immediate if operator) alterative.

"expression case ([default : default_expression ; ] c1 : expression1 ; c2 : expression2 ; c3 : expression3 ;....)"

If the default part is missing, the case() operator returns the value of the expression if it is not found in the collection of cases ( c1, c2, ...). For instance, if the value of expression is not any of c1, c2, .... the default_expression is executed and returned. If the value of the expression is c1, then the case() operator executes and returns the expression1. The default, c1, c2, c3, ... must be constant elements as numbers, dates or strings. For instance, the "date(shortdate(value)) case (default:0 ; #1/1/2002#:1 ; #2/1/2002#:1; #4/1/2002#:1; #5/1/2002#:1)" indicates that only #1/1/2002#, #2/1/2002#,  #4/1/2002# and  #5/1/2002# dates returns 1, since the others returns 0. For instance the following sample specifies the hour being non-working for specified dates: "date(shortdate(value)) case(default:0;#4/1/2009# : hour(value) >= 6 and hour(value) <= 12 ; #4/5/2009# : hour(value) >= 7 and hour(value) <= 10 or hour(value) in(15,16,18,22); #5/1/2009# : hour(value) <= 8)" statement indicates the working hours for dates as follows:

The in, switch and case() use binary search to look for elements so they are faster then using iif and or expressions.

Obviously, the priority of the operations inside the expression is determined by ( ) parenthesis and the priority for each operator. 

The supported conversion unary operators are:

Other known operators for numbers are:

Other known operators for strings are:

Other known operators for dates are:

The expression supports also immediate if ( similar with iif in visual basic, or ? : in C++ ) ie cond ? value_true : value_false, which means that once that cond is true the value_true is used, else the value_false is used. Also, it supports variables, up to 10 from 0 to 9. For instance, 0:="Abc" means that in the variable 0 is "Abc", and =:0 means retrieves the value of the variable 0. You can use variables to avoid computing several times the same thing.

The following VB sample shows how you can highlight the last Friday for each month::

With G2antt1
	With .Chart
		.PaneWidth(0) = 0
		.FirstVisibleDate = #1/17/2008#
		.LevelCount = 2
		.Level(1).FormatLabel = "(weekday(dvalue)=5 ? month(dvalue+7)!=month(dvalue) ? '<b><bgcolor=000000><fgcolor=FFFFFF>' ) +" & _
" value"
	End With
End With
The following VB sample shows how you can define your own labels and subdivisions:
With G2antt1
	.BeginUpdate 
	With .Chart
		.ToolTip = ""
		.PaneWidth(0) = 0
		.ScrollRange(exStartDate) = 0
		.ScrollRange(exEndDate) = 110
		.FirstVisibleDate = 0
		.ShowNonworkingDates = False
		.MarkTodayColor = .BackColor
		.LevelCount = 3
		With .Level(0)
			.ToolTip = ""
			.Alignment = CenterAlignment
			.Unit = exDay
			.Count = 16
			.FormatLabel = "'Group <b>'+int(1 +dvalue/16)"
		End With
		With .Level(1)
			.ToolTip = ""
			.Alignment = CenterAlignment
			.Unit = exDay
			.Count = 4
			.FormatLabel = " (abs(dvalue)/4) mod 4"
			.ReplaceLabel("0") = "Sub-Group <b>1</b>"
			.ReplaceLabel("1") = "Sub-Group <b>2</b>"
			.ReplaceLabel("2") = "Sub-Group <b>3</b>"
			.ReplaceLabel("3") = "Sub-Group <b>4</b>"
		End With
		With .Level(2)
			.ToolTip = ""
			.Unit = exDay
			.Count = 1
			.FormatLabel = "(abs(dvalue) mod 4)"
			.ReplaceLabel("0") = "A"
			.ReplaceLabel("1") = "B"
			.ReplaceLabel("2") = "C"
			.ReplaceLabel("3") = "D"
		End With
	End With
	.EndUpdate 
End With

The following VB.NET sample shows how you can highlight the last Friday for each month::

With AxG2antt1
	With .Chart
		.PaneWidth(0) = 0
		.FirstVisibleDate = #1/17/2008#
		.LevelCount = 2
		.Level(1).FormatLabel = "(weekday(dvalue)=5 ? month(dvalue+7)!=month(dvalue) ? '<b><bgcolor=000000><fgcolor=FFFFFF>' ) +" & _
" value"
	End With
End With
The following VB.NET sample shows how you can define your own labels and subdivisions:
With AxG2antt1
	.BeginUpdate 
	With .Chart
		.ToolTip = ""
		.PaneWidth(0) = 0
		.ScrollRange(EXG2ANTTLib.ScrollRangeEnum.exStartDate) = 0
		.ScrollRange(EXG2ANTTLib.ScrollRangeEnum.exEndDate) = 110
		.FirstVisibleDate = 0
		.ShowNonworkingDates = False
		.MarkTodayColor = .BackColor
		.LevelCount = 3
		With .Level(0)
			.ToolTip = ""
			.Alignment = EXG2ANTTLib.AlignmentEnum.CenterAlignment
			.Unit = EXG2ANTTLib.UnitEnum.exDay
			.Count = 16
			.FormatLabel = "'Group <b>'+int(1 +dvalue/16)"
		End With
		With .Level(1)
			.ToolTip = ""
			.Alignment = EXG2ANTTLib.AlignmentEnum.CenterAlignment
			.Unit = EXG2ANTTLib.UnitEnum.exDay
			.Count = 4
			.FormatLabel = " (abs(dvalue)/4) mod 4"
			.ReplaceLabel("0") = "Sub-Group <b>1</b>"
			.ReplaceLabel("1") = "Sub-Group <b>2</b>"
			.ReplaceLabel("2") = "Sub-Group <b>3</b>"
			.ReplaceLabel("3") = "Sub-Group <b>4</b>"
		End With
		With .Level(2)
			.ToolTip = ""
			.Unit = EXG2ANTTLib.UnitEnum.exDay
			.Count = 1
			.FormatLabel = "(abs(dvalue) mod 4)"
			.ReplaceLabel("0") = "A"
			.ReplaceLabel("1") = "B"
			.ReplaceLabel("2") = "C"
			.ReplaceLabel("3") = "D"
		End With
	End With
	.EndUpdate 
End With

The following C++ sample shows how you can highlight the last Friday for each month::

/*
	Copy and paste the following directives to your header file as
	it defines the namespace 'EXG2ANTTLib' for the library: 'ExG2antt 1.0 Control Library'

	#import <ExG2antt.dll>
	using namespace EXG2ANTTLib;
*/
EXG2ANTTLib::IG2anttPtr spG2antt1 = GetDlgItem(IDC_G2ANTT1)->GetControlUnknown();
EXG2ANTTLib::IChartPtr var_Chart = spG2antt1->GetChart();
	var_Chart->PutPaneWidth(0,0);
	var_Chart->PutFirstVisibleDate("1/17/2008");
	var_Chart->PutLevelCount(2);
	var_Chart->GetLevel(1)->PutFormatLabel(_bstr_t("(weekday(dvalue)=5 ? month(dvalue+7)!=month(dvalue) ? '<b><bgcolor=000000><fgcolor=FFFFFF>' ) +") +
" value");
The following C++ sample shows how you can define your own labels and subdivisions:
/*
	Copy and paste the following directives to your header file as
	it defines the namespace 'EXG2ANTTLib' for the library: 'ExG2antt 1.0 Control Library'

	#import <ExG2antt.dll>
	using namespace EXG2ANTTLib;
*/
EXG2ANTTLib::IG2anttPtr spG2antt1 = GetDlgItem(IDC_G2ANTT1)->GetControlUnknown();
spG2antt1->BeginUpdate();
EXG2ANTTLib::IChartPtr var_Chart = spG2antt1->GetChart();
	var_Chart->PutToolTip(L"");
	var_Chart->PutPaneWidth(0,0);
	var_Chart->PutScrollRange(EXG2ANTTLib::exStartDate,long(0));
	var_Chart->PutScrollRange(EXG2ANTTLib::exEndDate,long(110));
	var_Chart->PutFirstVisibleDate(long(0));
	var_Chart->PutShowNonworkingDates(VARIANT_FALSE);
	var_Chart->PutMarkTodayColor(var_Chart->GetBackColor());
	var_Chart->PutLevelCount(3);
	EXG2ANTTLib::ILevelPtr var_Level = var_Chart->GetLevel(0);
		var_Level->PutToolTip("");
		var_Level->PutAlignment(EXG2ANTTLib::CenterAlignment);
		var_Level->PutUnit(EXG2ANTTLib::exDay);
		var_Level->PutCount(16);
		var_Level->PutFormatLabel(L"'Group <b>'+int(1 +dvalue/16)");
	EXG2ANTTLib::ILevelPtr var_Level1 = var_Chart->GetLevel(1);
		var_Level1->PutToolTip("");
		var_Level1->PutAlignment(EXG2ANTTLib::CenterAlignment);
		var_Level1->PutUnit(EXG2ANTTLib::exDay);
		var_Level1->PutCount(4);
		var_Level1->PutFormatLabel(L" (abs(dvalue)/4) mod 4");
		var_Level1->PutReplaceLabel(L"0",L"Sub-Group <b>1</b>");
		var_Level1->PutReplaceLabel(L"1",L"Sub-Group <b>2</b>");
		var_Level1->PutReplaceLabel(L"2",L"Sub-Group <b>3</b>");
		var_Level1->PutReplaceLabel(L"3",L"Sub-Group <b>4</b>");
	EXG2ANTTLib::ILevelPtr var_Level2 = var_Chart->GetLevel(2);
		var_Level2->PutToolTip("");
		var_Level2->PutUnit(EXG2ANTTLib::exDay);
		var_Level2->PutCount(1);
		var_Level2->PutFormatLabel(L"(abs(dvalue) mod 4)");
		var_Level2->PutReplaceLabel(L"0",L"A");
		var_Level2->PutReplaceLabel(L"1",L"B");
		var_Level2->PutReplaceLabel(L"2",L"C");
		var_Level2->PutReplaceLabel(L"3",L"D");
spG2antt1->EndUpdate();

The following C# sample shows how you can highlight the last Friday for each month::

EXG2ANTTLib.Chart var_Chart = axG2antt1.Chart;
	var_Chart.set_PaneWidth(0 != 0,0);
	var_Chart.FirstVisibleDate = "1/17/2008";
	var_Chart.LevelCount = 2;
	var_Chart.get_Level(1).FormatLabel = "(weekday(dvalue)=5 ? month(dvalue+7)!=month(dvalue) ? '<b><bgcolor=000000><fgcolor=FFFFFF>' ) +" +
" value";
The following C# sample shows how you can define your own labels and subdivisions:
axG2antt1.BeginUpdate();
EXG2ANTTLib.Chart var_Chart = axG2antt1.Chart;
	var_Chart.ToolTip = "";
	var_Chart.set_PaneWidth(0 != 0,0);
	var_Chart.set_ScrollRange(EXG2ANTTLib.ScrollRangeEnum.exStartDate,0);
	var_Chart.set_ScrollRange(EXG2ANTTLib.ScrollRangeEnum.exEndDate,110);
	var_Chart.FirstVisibleDate = 0;
	var_Chart.ShowNonworkingDates = false;
	var_Chart.MarkTodayColor = var_Chart.BackColor;
	var_Chart.LevelCount = 3;
	EXG2ANTTLib.Level var_Level = var_Chart.get_Level(0);
		var_Level.ToolTip = "";
		var_Level.Alignment = EXG2ANTTLib.AlignmentEnum.CenterAlignment;
		var_Level.Unit = EXG2ANTTLib.UnitEnum.exDay;
		var_Level.Count = 16;
		var_Level.FormatLabel = "'Group <b>'+int(1 +dvalue/16)";
	EXG2ANTTLib.Level var_Level1 = var_Chart.get_Level(1);
		var_Level1.ToolTip = "";
		var_Level1.Alignment = EXG2ANTTLib.AlignmentEnum.CenterAlignment;
		var_Level1.Unit = EXG2ANTTLib.UnitEnum.exDay;
		var_Level1.Count = 4;
		var_Level1.FormatLabel = " (abs(dvalue)/4) mod 4";
		var_Level1.set_ReplaceLabel("0","Sub-Group <b>1</b>");
		var_Level1.set_ReplaceLabel("1","Sub-Group <b>2</b>");
		var_Level1.set_ReplaceLabel("2","Sub-Group <b>3</b>");
		var_Level1.set_ReplaceLabel("3","Sub-Group <b>4</b>");
	EXG2ANTTLib.Level var_Level2 = var_Chart.get_Level(2);
		var_Level2.ToolTip = "";
		var_Level2.Unit = EXG2ANTTLib.UnitEnum.exDay;
		var_Level2.Count = 1;
		var_Level2.FormatLabel = "(abs(dvalue) mod 4)";
		var_Level2.set_ReplaceLabel("0","A");
		var_Level2.set_ReplaceLabel("1","B");
		var_Level2.set_ReplaceLabel("2","C");
		var_Level2.set_ReplaceLabel("3","D");
axG2antt1.EndUpdate();

The following VFP sample shows how you can highlight the last Friday for each month::

with thisform.G2antt1
	with .Chart
		.PaneWidth(0) = 0
		.FirstVisibleDate = {^2008-1-17}
		.LevelCount = 2
		var_s = "(weekday(dvalue)=5 ? month(dvalue+7)!=month(dvalue) ? '<b><bgcolor=000000><fgcolor=FFFFFF>' ) + "
		var_s = var_s + "value"
		.Level(1).FormatLabel = var_s
	endwith
endwith
The following VFP sample shows how you can define your own labels and subdivisions:
with thisform.G2antt1
	.BeginUpdate
	with .Chart
		.ToolTip = ""
		.PaneWidth(0) = 0
		.ScrollRange(0) = 0
		.ScrollRange(1) = 110
		.FirstVisibleDate = 0
		.ShowNonworkingDates = .F.
		.MarkTodayColor = .BackColor
		.LevelCount = 3
		with .Level(0)
			.ToolTip = ""
			.Alignment = 1
			.Unit = 4096
			.Count = 16
			.FormatLabel = "'Group <b>'+int(1 +dvalue/16)"
		endwith
		with .Level(1)
			.ToolTip = ""
			.Alignment = 1
			.Unit = 4096
			.Count = 4
			.FormatLabel = " (abs(dvalue)/4) mod 4"
			.ReplaceLabel("0") = "Sub-Group <b>1</b>"
			.ReplaceLabel("1") = "Sub-Group <b>2</b>"
			.ReplaceLabel("2") = "Sub-Group <b>3</b>"
			.ReplaceLabel("3") = "Sub-Group <b>4</b>"
		endwith
		with .Level(2)
			.ToolTip = ""
			.Unit = 4096
			.Count = 1
			.FormatLabel = "(abs(dvalue) mod 4)"
			.ReplaceLabel("0") = "A"
			.ReplaceLabel("1") = "B"
			.ReplaceLabel("2") = "C"
			.ReplaceLabel("3") = "D"
		endwith
	endwith
	.EndUpdate
endwith

 


Send comments on this topic.
© 1999-2012 Exontrol.COM, Software. All rights reserved.