pChart 2.x forum
http://wiki.pchart.net/forum/

Radar charts
http://wiki.pchart.net/forum/viewtopic.php?f=5&t=49
Page 1 of 1

Author:  yoh [ Wed Jan 05, 2011 5:34 pm ]
Post subject:  Radar charts

Hi,

I'm currently using pChart 2.0.10 and have a little bug when creating radar chart :

ImageImage

As you can see, segments labels (1,2,3...) are a bit out of the line. I tried to solve it myself... Help! :D

Here is my code :
Code:
$etiquettes = array('1','2','3','4');
// $etiquettes2 = array('1','2','3','4','5');

$valeurs = array('Serie 1', array(1,2,1,2));
// $valeurs2 = array('Serie 1', array(1,2,1,2,1));

$titre = 'Titre';

$MyData = new pData();

$MyData->addPoints($valeurs[1],"Serie1");
$MyData->setSerieDescription("Serie1",$valeurs[0]);
// $MyData->addPoints($valeurs2[1],"Serie1");
// $MyData->setSerieDescription("Serie1",$valeurs2[0]);

/* Définition des noms de branches */
$MyData->addPoints($etiquettes,"Labels");
// $MyData->addPoints($etiquettes2,"Labels");
$MyData->setAbscissa("Labels");

/* Création de l'objet pChart */
$myPicture = new pImage(400,350,$MyData);
$RectangleSettings = array("R"=>180,"G"=>180,"B"=>180,"Alpha"=>100);

/* Titre du graph */
$myPicture->setFontProperties(array("FontName"=>"./pChart2/fonts/verdana.ttf","FontSize"=>10));
$myPicture->drawText(195,20,$titre,array("R"=>100,"G"=>100,"B"=>100,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
$myPicture->drawRoundedRectangle(5,5,395,40,5,array("R"=>100,"G"=>100,"B"=>100));

/* Définition de la police par défaut */
$myPicture->setFontProperties(array("FontName"=>"./pChart2/fonts/verdana.ttf","FontSize"=>9,"R"=>80,"G"=>80,"B"=>80));

/* Création de l'objet pRadar */
$SplitChart = new pRadar();

/* Dessin du graph radar */
$myPicture->setGraphArea(10,50,390,310);
$Options = array("SegmentHeight"=>1,"Segments"=>5,"DrawPoly"=>true,"DrawPoints"=>false,"Layout"=>RADAR_LAYOUT_STAR,"LabelsBGR"=>240,"LabelsBGG"=>240,"LabelsBGB"=>240,"LabelPos"=>RADAR_LABELS_HORIZONTAL,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>235,"EndG"=>235,"EndB"=>235,"EndAlpha"=>20));
$SplitChart->drawRadar($myPicture,$MyData,$Options);

/* Sortie du graph (fichier) */
$myPicture->Render('radar.png');


If you have a solution...

Thanks :)

Author:  jean-damien [ Thu Jan 06, 2011 8:53 am ]
Post subject:  Re: Radar charts

Thanks for posting this bug!

This issue only popup with RADAR_LAYOUT_STAR radar charts. To correct it, replace the code section that is writting the axis labels located after

Code:
       $Options["FontSize"] = $AxisFontSize;


by :

Code:
       $Angle  = 360 / ($Points*2);
       for($j=1;$j<=$Segments;$j++)
        {
         $Label  = $j * $SegmentHeight;

         if ( $Layout == RADAR_LAYOUT_CIRCLE )
          {
           $EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
           $EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
          }
         elseif ( $Layout == RADAR_LAYOUT_STAR )
          {
           $EdgeX1 = cos(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
           $EdgeY1 = sin(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
           $EdgeX2 = cos(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
           $EdgeY2 = sin(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;

           $EdgeX1 = ($EdgeX2 - $EdgeX1)/2 + $EdgeX1;
           $EdgeY1 = ($EdgeY2 - $EdgeY1)/2 + $EdgeY1;
          }

         $Object->drawText($EdgeX1,$EdgeY1,$Label,$Options);
        }


I'll apply this fix in the 2.0.11.

Kind regards,
JD.

Author:  yoh [ Thu Jan 06, 2011 9:21 am ]
Post subject:  Re: Radar charts

It works perfectly !
Thanks :mrgreen:

Author:  jean-damien [ Thu Jan 06, 2011 9:35 am ]
Post subject:  Re: Radar charts

Thank you for having noticed it ;o)

Author:  jean-damien [ Fri Jan 07, 2011 3:57 pm ]
Post subject:  Re: Radar charts

I've posted the new 2.0.11 subversion on the pChart web site correcting this bug.

You can get it here : http://www.pchart.net/download

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/