Fig 1: Simple Pie Chart.
To configure the legend, use the following properties:
Fig 2: Simple Pie Chart: legend configured.
The percentages are computed automatically and added into the legend. Pie Charts - Data Based
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Define variables to be used including a temporary table c_values = "" c_names = "" c_table = "_" + tmpnam() // Open the database and extract the data into the temporary table exec sql open database southwind; exec sql select count(orderid) orders, employees.firstname forename, employees.lastname surname from orders, employees where orders.employeeid = employees.employeeid group by employeeid save as &c_table; |
Traverse the temporary table using the 4GL SCAN command to build up the comma-separated strings: c_values with the number of orders, c_names with the shipping company names.
// Scan the table to build up the strings
use &c_table
scan
c_values = c_values + ltrim(str(orders))+","
c_names = c_names + trim(forename)+" "+trim(surname)+","
endscan
|
The c_values variable can then be used as the pie chart's data property and the c_names variable as the xValueLabels property.
Define the graph, macro-substituting the c_values and c_names variables (using the 4GL & macro operator).
// Define the graph
@02,05 to 13,48 properties "control=graphcontrol;;
id=chart1;;
type=pie;;
data=&c_values;;
xValueLabels=&c_names;;
pixelxLegend=275;;
pixelyLegend=5;;
pixelWidthLegend=160;;
pixelHeightLegend=150"
read
|
Complete source:
// Define variables to be used including a temporary table c_values = "" c_names = "" c_table = "_" + tmpnam() // Open the database and extract the data into the temporary table exec sql open database southwind; exec sql select count(orderid) orders, employees.firstname forename, employees.lastname surname from orders, employees where orders.employeeid = employees.employeeid group by employee save as &c_table; // Scan the table to build up the strings use &c_table scan c_values = c_values + ltrim(str(orders))+"," c_names = c_names + trim(forename)+" "+trim(surname)+"," endscan // Define the graph @02,05 to 13,48 properties "control=graphcontrol;; id=chart1;; type=pie;; data=&c_values;; xValueLabels=&c_names;; pixelxLegend=275;; pixelyLegend=5;; pixelWidthLegend=160;; pixelHeightLegend=15" read close databases |
The pie chart graph control has an onDoubleClick event handler that can be used to 'drill down' into individual pie segments when the legend pie label is double-clicked. The label is passed as a parameters to the procedure associated with the onDoubleClick event handler:
|
Parameter |
Data Type |
Description |
|
DataLabel |
Character |
Data label, corresponds to 'xValueLabels' text for the pie segment. |
The procedure is defined as follows:
@02,05 to 13,48 properties "control=graphcontrol;; id=chart1;; type=pie;; data=&c_values;; xValueLabels=&c_names;; pixelxLegend=275;; pixelyLegend=5;; pixelWidthLegend=160;; pixelHeightLegend=150;; onDoubleClick=pie_drilldown" |
At its simplest, the event procedure could display the pie segment's exact data value:
Click image to display full size
Fig 4: Simple Drill Down Event.
procedure pie_drilldown parameter DataLabel exec sql select orders from &c_table where trim(forename)+ " " + trim(surname) = DataLabel into n_orders; dialog box DataLabel + " has " + ltrim(etos(n_orders))+ " orders." return c_values = "" c_names = "" c_table = "_" + tmpnam() exec sql open database southwind; exec sql select count(orderid) orders, employees.firstname forename, employees.lastname surname from orders, employees where orders.employeeid = employees.employeeid group by employee save as &c_table; use &c_table scan c_values = c_values + ltrim(str(orders))+"," c_names = c_names + trim(forename)+" "+trim(surname)+"," endscan @02,05 to 13,48 properties "control=graphcontrol;; id=chart1;; type=pie;; data=&c_values;; xValueLabels=&c_names;; pixelxLegend=275;; pixelyLegend=5;; pixelWidthLegend=160;; pixelHeightLegend=15;; onDoubleClick=pie_drilldown" read close databases |
The drill down event procedure can also be used to change a chart's properties. The mirage_demo application which is included in the Recital Visual Developer distribution gives an example of this for a Bar Chart, demonstrating the use of the SHOW OBJECT command.
Part 1 of this article, covering Bar Charts, gives as example where drilling into an orders by Shipping Company bar chart displays a second bar chart based on a new SQL query, breaking down the orders by shipping company by the id number of the employee who took the order. This second bar chart also has an onDoubleClick event, showing the exact number of orders by employee name.
Here we drill down into our Pie Chart to show all the orders by a particular employee in grid format in a listbox control:
Click image to display full size
Fig 5: Drill Down Event.
Procedure pie_drilldown parameter DataLabel exec sql select orders.orderid, orders.customerid, orders.orderdate, orders.requireddate from orders inner join employees on orders.employeeid = employees.employeeid where trim(employees.firstname)+ " " + trim(employees.lastname) = Datalabel into array temp; store 0 to mlistbox @15,05 get mlistbox; from temp; function "&T"; size 8,43; properties "columnTitles=Order,Customer,Ordered,Required;; columnWidths=C10,C5,C8,C8" show object mlistbox properties "command=show" return c_values = "" c_names = "" c_table = "_" + tmpnam() exec sql open database southwind; exec sql select count(orderid) orders, employees.firstname forename, employees.lastname surname from orders, employees where orders.employeeid = employees.employeeid group by employee save as &c_table; use &c_table scan c_values = c_values + ltrim(str(orders))+"," c_names = c_names + trim(forename)+" "+trim(surname)+"," endscan @02,05 to 13,48 properties "control=graphcontrol;; id=chart1;; type=pie;; data=&c_values;; xValueLabels=&c_names;; pixelxLegend=275;; pixelyLegend=5;; pixelWidthLegend=160;; pixelHeightLegend=15;; onDoubleClick=pie_drilldown" read close databases |
There is a range of further properties that can be used to configure the display of the Pie Chart:
|
Property |
Example |
Description |
|
borderColor |
borderColor=red |
The foreground color of the border. |
|
borderWidth |
borderWidth=3 |
The width of the border line. |
|
shadowStyle |
shadowStyle=etchedOut |
The shadowing effect style: raised, recessed, etchedIn, etchedOut. The shadowing effect is only available if borderWidth is 0 or not specified. |
|
shadowWidth |
shadowWidth=3 |
The width in pixels of the shadowing effect. |
|
wallpaper |
wallpaper=+gradient_blue.gif |
The background, 'wallpaper' image. The image file name can be preceded by a '-' to tile the image to fit or by a '+' to stretch the image to fit. |
|
labelForeColor |
labelForeColor=blue |
The foreground color of the legend labels (xValueLabels). |
|
colorData |
colorData=red,yellow,green |
The pie segment colors. The default colors are: blue, red, green, yellow, aqua, pink, fuchsia, gray, orange, navy, white, coral, beige, paleturquoise, darkgray. These are repeated as required |
Click image to display full size
Fig 6: Pie Chart with additional display properties set.
@02,05 to 13,48 properties "control=graphcontrol;; id=chart1;; type=pie;; data=&c_values;; xValueLabels=&c_names;; pixelxLegend=275;; pixelyLegend=5;; pixelWidthLegend=160;; pixelHeightLegend=150;; onDoubleClick=pie_drilldown;; borderColor=navy;; borderWidth=3;; wallpaper=+gradient_blue.gif;; labelForeColor=blue;; colorData=red,yellow,pink,green,orange,purple,blue,black,white" read |
Setting multiple properties can lead to a "String is too long" error. In which case the properties should be split between the original control definition and one or more subsequent SHOW OBJECT...properties "command=properties" commands:
@02,05 to 13,48 properties "control=graphcontrol;; id=chart1;; type=pie;; data=&c_values;; xValueLabels=&c_names;; pixelxLegend=275;; pixelyLegend=5;; pixelWidthLegend=160;; pixelHeightLegend=150;; onDoubleClick=pie_drilldown;; borderColor=navy;; borderWidth=3;; wallpaper=+gradient_blue.gif;; labelForeColor=blue" show object "graphcontrol" properties "command=properties;id=chart1;; colorData=darkred,yellow,lightpink,darkolivegreen,orange,purple,blue,black,white" read |
The following color names can be used by the Mirage .NET client.
|
Colors |
|||
|---|---|---|---|
|
aliceblue |
darkslategray |
lightseagreen |
papayawhip |