Tech Tip: Graphing the number of occurrences of distinct values
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: April 19, 2017
From Tech Tip #77721, the method DISTINCT_ATTR_VALUES_COUNT will find the number occurrences of each distinct values found in a given object field selection. This method will visually display the results with the graph command as shown below:
// -------------------------------------------------------------------------------- // Name: GRAPH_DIST_ATTR_VAL_CNT // Description: Method will look at the selected field object records and extract // the distinct values of a property and number of occurrances then graph it. // Input: // $1 (LONGINT) - Graph choice (#1-8 from the GRAPH command) // $2 (POINTER) - Pointer to the Object field // $3 (TEXT) - Attribute name to find the number occurrances // // Output: // $0 (POINTER) - Graph picture // -------------------------------------------------------------------------------- C_LONGINT($1;$graphChoice;$type) C_POINTER($2;$fieldPtr) C_TEXT($3;$attr) C_PICTURE($0;$graphPic) ARRAY LONGINT($distVCnt;0) If (Count parameters=3) $graphChoice:=$1 $fieldPtr:=$2 $attr:=$3 $fieldPtr:=Field(Table($fieldPtr);Field($fieldPtr)) // Figure out the type because we don't know the type $type:=OB Get type($fieldPtr->;$attr) //Execute formula to determine the type of array to create Case of : ($type=Is text) ARRAY TEXT($distAttrVArrT;0) DISTINCT_ATTR_VALUES_COUNT ($fieldPtr;$attr;->$distAttrVArrT;->$distVCnt)  GRAPH($graphPic;$graphChoice;$distAttrVArrT;$distVCnt) //Draw the graph : ($type=Is real) ARRAY LONGINT($distAttrVArrNum;0) DISTINCT_ATTR_VALUES_COUNT ($fieldPtr;$attr;->$distAttrVArrNum;->$distVCnt)  GRAPH($graphPic;$graphChoice;$distAttrVArrNum;$distVCnt) //Draw the graph : ($type=Is Boolean) ARRAY BOOLEAN($distAttrVArrBool;0) DISTINCT_ATTR_VALUES_COUNT ($fieldPtr;$attr;->$distAttrVArrBool;->$distVCnt)  GRAPH($graphPic;$graphChoice;$distAttrVArrBool;$distVCnt) //Draw the graph : ($type=Is time) ARRAY TIME($distAttrVArrTime;0) DISTINCT_ATTR_VALUES_COUNT ($fieldPtr;$attr;->$distAttrVArrTime;->$distVCnt)  GRAPH($graphPic;$graphChoice;$distAttrVArrTime;$distVCnt) //Draw the graph Else End case GRAPH SETTINGS($graphPic;0;0;0;0;False;False;True;$attr) //Set the legends $0:=$graphPic End if |
Here are a set of data in finding occurances of age.
Using the DISTINCT_ATTR_VALUES_COUNT results to these number of occurrances for each distinct value:
Example #1: Graphing the occurrances with option #4:
C_LONGINT($graphType) C_PICTURE($graphPicture) C_TEXT($attr) ALL RECORDS([Table_1]) $attr:="Age" $graphType:=4 $graphPicture:=GRAPH_DIST_ATTR_VAL_CNT ($graphType;->[Table_1]Field_obj;$attr) |
Result:
Example #2: Graphing the occurrances with option #5:
$graphType:=5 $graphPicture:=GRAPH_DIST_ATTR_VAL_CNT ($graphType;->[Table_1]Field_obj;$attr) |
Result:
Example #3: Graphing the occurrances with option #7:
$graphType:=7 $graphPicture:=GRAPH_DIST_ATTR_VAL_CNT ($graphType;->[Table_1]Field_obj;$attr) |
Result:
Example #4: Graphing the occurrances with option #8:
$graphType:=8 $graphPicture:=GRAPH_DIST_ATTR_VAL_CNT ($graphType;->[Table_1]Field_obj;$attr) |
Result: