PHP Pie Chart: Just for DMX and php_mysql Server Model: This extension will let you create pie charts (using percentages) from a Recordset.
The extension won't create the Recordset: It just draws the chart according to the results. The recordset must return, at least, a field with numeric data and the extension will calculate the percentage for each value and it will put it in the pie chart. Let's see an example: We've got the tables "companies" and "sales":
COMPAPNIES |
|
SALES |
id_company |
company_name |
id_sale |
id_company |
amount |
1 |
Microsoft |
1 |
2 |
2 |
2 |
Adobe |
2 |
3 |
150 |
3 |
Macromedia |
3 |
1 |
55 | You can see that there's a relationship between them (the field "id_company") and we want to guess the sales percentage for each company. Our Recordset could be: SELECT SUM(amount),company_name FROM sales, companies WHERE sales.id_company=companies.id_company GROUP BY companies.id_comapny
this Recordset will display:
company_name |
amount |
Microsoft |
55 |
Macromedia |
150 |
Adobe |
2 | With this recordset, we can use the extension:
Recordset: Select the name of your Recordset.
Display: You can uncheck it if you only want to show the percentages in the pie chart without legend.
Label Field: This field should show the label attached to every percentage (the company name, in our example).
Data Field: Select which field stores the numeric data ("amount" in our example).
Font Size: Select a font size for your label.
minPercent: You must indicate the smallest percentage the pie chart should display. All values smaller than this will be grouped as "Other". remember that 0.01 equals 1% and 1.00 equals 100%. In the picture, you can see that all values smaller than 22% (0.22) will be grouped as "Other".
Width / Height: with and height for the pie chart image.
BgColor: Background color.
Linecolor: Color for the lines that separate every piece of the chart.
Color1...color8: colores for each piece. If the chart displays more than 8 results, color 1 will be used again and so on.
See a Demo
Limitations:
To use this extension, your PHP must have support for GD 1.6 or above.
Remember that, when using this extension, You can't add anything else to your document. Don't use it embedded into a normal document: If you want to embed the resulting chart in a document, you must link to it as if it were a common image. How can you do it? It's easy:
For example. You have saved the php file with the code to "draw" the chart as "chart.php" and you want to show it in another document, called "companies.php". Open this file in DWMX, Select "insert Image" and select the file "chart.php":
<img src="images/chart.php">
If your recordset need some parameters, you can add it to the path:
<img src="images/chart.php?yourparam=44">
And the pie chart will be shown as an image in your document.
Download it here
Acknowledgements: This extension has been made with code written byJames Heinrich, from silisoftware. In his site you'll find more useful PHP scripts.Thanks, James.
|