Contents
Login Register Wishes Forum About
Language Reference » Radar & Polar charts » drawPolar
Help topics
Latest updates
2028d  replaceImageMapTitle
2028d  replaceImageMapValues
2028d  createFunctionSerie
2028d  setAbsicssaPosition
2028d  negateValues
Toolbox
  Download as PDF
  Print this page
  Share this page
  Create an account
  Feed the updates!
Google AdSense
drawPolar - Draw polar charts

This function allows you to draw a polar chart. All the drawing parameters are given trough a $Format array. To learn more about this please read the Format array guide. Polar charts were not existing in pChart 1.x. Best is to keep the scale computing to automatic (SEGMENT_HEIGHT_AUTO) to have the most eye candy rendering.

Polar charts share many parameters with the radar charts. The main difference is that the X axis is fixed to 0-360, data is given using the common way with the pData class, X values of the associated points are given through the abscissa serie which is then mandatory.

Calling this function
drawPolar($Object,$Values,$Format);
Where :

Object is reference to a pImage object.
Values is reference to a pData object.
Format is an array containing the drawing parameters of the chart.


Customisation array - Tune up your chart!

It is possible to customize the polar chart rendering by playing with this array. Providing a detailled configuration is not mandatory. You‘ll see below a representation of all the customization possible :

You can specify if the axis color with AxisR, AxisG, AxisB, AxisAlpha.
You can fix the maximum value of the branches with FixedMax even if never reached.
You can specify the axis rotation in degree using AxisRotation.
You can specify the step in degree between two axis lines with AxisSteps. (default is 20°)
You can draw ticks outside of the radard setting DrawTicks to TRUE.
You can define the ticks length with TicksLength (default is 2px)
You can write the axis names setting DrawAxisValues to TRUE.
You can write the axis names in a rounded box setting AxisBoxRounded to TRUE.
You can choose the axis font settings with AxisFontName and AxisFontSize.
You can write the points values setting WriteValues to TRUE.
You can write the values in a bubble setting WriteValuesInBubble to TRUE.
You can choose the values font settings with ValueFontName and ValueFontSize.
You can specify an extra padding for the values with ValuePadding.
You can tune the outter bubble visual parameters with OuterBubbleRadius,OuterBubbleR,OuterBubbleG,OuterBubbleB,OuterBubbleAlpha.
You can tune the inner bubble visual parameters with InnerBubbleR,InnerBubbleG,InnerBubbleB,InnerBubbleAlpha.
You can specify the position of the axis names with LabelPos (see below).
You can specify the label paddings with LabelPadding (default is 4px).
You can draw a background setting DrawBackground to TRUE.
You can specify the background color with BackgroundR, BackgroundG, BackgroundB, BackgroundAlpha.
You can specify a background gradient with BackgroundGradient see the details below .
You can define the radar layout with Layout see the details below .
You can specify the height of one segment manually with SegmentHeight (default is SEGMENT_HEIGHT_AUTO for automatic computation)
You can specify the number of segments manually with Segments (this may be overwritten if you use SEGMENT_HEIGHT_AUTO)
You can write the segments values setting WriteLabels to TRUE.
You can specify if the segment values should have background setting LabelsBackground to TRUE.
You can specify the segments values background color with LabelsBGR, LabelsBGG, LabelsBGB, LabelsBGAlpha.
You can specify if you want to draw a circle for each data point setting DrawPoints to TRUE.
You can specify the radius of the circles with PointRadius. (default is 4)
You can specify a surrounding color around the circles with PointSurrounding. (default is -30)
You can specify if you want to draw lines between each data point setting DrawLines to TRUE.
You define if lines should loop to the 1st data point setting LineLoopStart to TRUE.
You can specify if you want to draw polygons with your data points setting DrawPoly to TRUE.
You can overide the polygons transparency with PolyAlpha.

The Layout (Layout) can be :

RADAR_LAYOUT_STAR, this will draw star like axis.
RADAR_LAYOUT_CIRCLE, this will draw concentric circles axis.

The labels positions (LabelPos) can be :

RADAR_LABELS_ROTATED, this will written with an angle depending of the axis position.
RADAR_LABELS_HORIZONTAL, labels will be written horizontally.

Gradients are defined with an array containing 8 values :

The starting color defined by StartR, StartG, StartB, StartAlpha.
The ending color defined by EndR, EndG, EndB, EndAlpha.

$Gradient = array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>50,"EndR"=>32,"EndG"=>109,"EndB"=>174,"EndAlpha"=>30)

Sample script


 /* pChart library inclusions */
 include("../class/pData.class.php");
 include("../class/pDraw.class.php");
 include("../class/pRadar.class.php");
 include("../class/pImage.class.php");

 /* Create and populate the pData object */
 $MyData = new pData();   
 $MyData->addPoints(array(10,20,30,40,50,60,70,80,90),"ScoreA"); 
 $MyData->addPoints(array(20,40,50,12,10,30,40,50,60),"ScoreB"); 
 $MyData->setSerieDescription("ScoreA","Coverage A");
 $MyData->setSerieDescription("ScoreB","Coverage B");

 /* Define the absissa serie */
 $MyData->addPoints(array(40,80,120,160,200,240,280,320,360),"Coord");
 $MyData->setAbscissa("Coord");

 /* Create the pChart object */
 $myPicture = new pImage(700,230,$MyData);

 /* Draw a solid background */
 $Settings = array("R"=>179, "G"=>217, "B"=>91, "Dash"=>1, "DashR"=>199, "DashG"=>237, "DashB"=>111);
 $myPicture->drawFilledRectangle(0,0,700,230,$Settings);

 /* Overlay some gradient areas */
 $Settings = array("StartR"=>194, "StartG"=>231, "StartB"=>44, "EndR"=>43, "EndG"=>107, "EndB"=>58, "Alpha"=>50);
 $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
 $myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>100));

 /* Add a border to the picture */
 $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));

 /* Write the picture title */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Silkscreen.ttf","FontSize"=>6));
 $myPicture->drawText(10,13,"pRadar - Draw polar charts",array("R"=>255,"G"=>255,"B"=>255));

 /* Set the default font properties */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>10,"R"=>80,"G"=>80,"B"=>80));

 /* Enable shadow computing */ 
 $myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));

 /* Create the pRadar object */ 
 $SplitChart = new pRadar();

 /* Draw a polar chart */ 
 $myPicture->setGraphArea(10,25,340,225);
 $Options = array("BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50));
 $SplitChart->drawPolar($myPicture,$MyData,$Options);

 /* Draw a polar chart */ 
 $myPicture->setGraphArea(350,25,690,225);
 $Options = array("LabelPos"=>RADAR_LABELS_HORIZONTAL,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255, "StartAlpha"=>50,"EndR"=>32,"EndG"=>109,"EndB"=>174,"EndAlpha"=>30),"AxisRotation"=>0,"DrawPoly"=>TRUE, "PolyAlpha"=>50);
 $SplitChart->drawPolar($myPicture,$MyData,$Options);

 /* Write the chart legend */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.ttf","FontSize"=>6));
 $myPicture->drawLegend(270,205,array("Style"=>LEGEND_BOX,"Mode"=>LEGEND_HORIZONTAL));

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("pictures/example.polar.png");

Sample script #2


 /* pChart library inclusions */
 include("../class/pData.class.php");
 include("../class/pDraw.class.php");
 include("../class/pRadar.class.php");
 include("../class/pImage.class.php");

 /* Create and populate the pData object */
 $MyData = new pData();   
 $MyData->addPoints(array(10,20,30,40,50,60,70,80,90),"ScoreA"); 
 $MyData->addPoints(array(20,40,50,12,10,30,40,50,60),"ScoreB"); 
 $MyData->setSerieDescription("ScoreA","Coverage A");
 $MyData->setSerieDescription("ScoreB","Coverage B");

 /* Define the absissa serie */
 $MyData->addPoints(array(40,80,120,160,200,240,280,320,360),"Coord");
 $MyData->setAbscissa("Coord");

 /* Create the pChart object */
 $myPicture = new pImage(300,300,$MyData);
 $myPicture->drawGradientArea(0,0,300,300,DIRECTION_VERTICAL,array("StartR"=>200,"StartG"=>200,"StartB"=>200,"EndR"=>240,"EndG"=>240,"EndB"=>240,"Alpha"=>100));
 $myPicture->drawGradientArea(0,0,300,20,DIRECTION_HORIZONTAL,array("StartR"=>30,"StartG"=>30,"StartB"=>30,"EndR"=>100,"EndG"=>100,"EndB"=>100,"Alpha"=>100));
 $myPicture->drawLine(0,20,300,20,array("R"=>255,"G"=>255,"B"=>255));
 $RectangleSettings = array("R"=>180,"G"=>180,"B"=>180,"Alpha"=>100);

 /* Add a border to the picture */
 $myPicture->drawRectangle(0,0,299,299,array("R"=>0,"G"=>0,"B"=>0));

 /* Write the picture title */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Silkscreen.ttf","FontSize"=>6));
 $myPicture->drawText(10,13,"pRadar - Draw radar charts",array("R"=>255,"G"=>255,"B"=>255));

 /* Set the default font properties */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>10,"R"=>80,"G"=>80,"B"=>80));

 /* Enable shadow computing */ 
 $myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));

 /* Create the pRadar object */ 
 $SplitChart = new pRadar();

 /* Draw a radar chart */ 
 $myPicture->setGraphArea(10,25,290,290);
 $Options = array("DrawPoly"=>TRUE,"WriteValues"=>TRUE,"ValueFontSize"=>8,"Layout"=>RADAR_LAYOUT_CIRCLE,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50));
 $SplitChart->drawPolar($myPicture,$MyData,$Options);

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("pictures/example.polar.values.png");
Last updated on 12/08/2010 
by Jean-Damien 
Linked resources
  There is no linked topic yet.
Community comments
  No comments have been posted yet.
© Copyrights
Components used on this web site : Famfamfam icons has been made by Mark James, Rounded corners lite has been coded by Cameron Cooke and Tim Hutchison, SyntaxHighlighter has been written by Alex Gorbatchev. pChart and this web site have been created by Jean-Damien POGOLOTTI. This documentation contains 185 pages and 56 comments. 409 users have registered. This page has been rendered in 0,01 seconds. Wiki revision 1.37.