View unanswered posts | View active topics It is currently Thu May 16, 2024 12:41 pm



Reply to topic  [ 6 posts ] 
Bar Chart bug? with bars too wide 
Author Message
New pChart user
New pChart user

Joined: Thu Jan 06, 2011 12:45 pm
Posts: 3
Post Bar Chart bug? with bars too wide
this may be a bug - or i need to set something but i'm not sure.

if i have lots of points per item, pChart doesn't size the bars correctly and overlaps the scale etc.

Please help - i am really liking pChart!

Attachment:
alan2.png
alan2.png [ 17.04 KiB | Viewed 8734 times ]


Code:

<?php
include("class/pData.class");
include("class/pDraw.class");
include("class/pImage.class");

$MyData = new pData();


$MyData->addPoints(5  ,'c1');
$MyData->addPoints(10  ,'c2');
$MyData->addPoints(15  ,'c3');
$MyData->addPoints( 8 ,'c4');
$MyData->addPoints( 7 ,'c5');

$gamePoints = array('lots');

$MyData->setAxisName(0,"Days");
$MyData->addPoints($gamePoints,"Games");
$MyData->setSerieDescription("Games","Game");
$MyData->setAbscissa("Games");


$chartHieght = 200;

/* Create the pChart object */
$myPicture = new pImage(1100,$chartHieght+200,$MyData);
$myPicture->drawGradientArea(0,0,1000,$chartHieght,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
$myPicture->drawGradientArea(0,0,1000,$chartHieght,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));
$myPicture->setFontProperties(array("FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>8));

/* Draw the scale  */
$myPicture->setGraphArea(200,50,950,$chartHieght-20);
$myPicture->drawScale(array('Mode' => SCALE_MODE_START0, "CycleBackground"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,"Pos"=>SCALE_POS_TOPBOTTOM));

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

/* Draw the chart */
$settings = array("Gradient"=>TRUE,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>255,"DisplayG"=>255,"DisplayB"=>255,"DisplayShadow"=>TRUE,"Surrounding"=>10);
$myPicture->drawBarChart($settings);

/* Write the chart legend */
$myPicture->drawLegend(150,10,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));


/* Render the picture (choose the best way) */
$myPicture->render("alan2.png");
?>
<img src="alan2.png"  />


Thu Jan 06, 2011 12:53 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: Bar Chart bug? with bars too wide
Hi,

This is a bug that occurs when you have only one absissa value. Let me dig into it!

JD.


Thu Jan 06, 2011 2:13 pm
Profile WWW
New pChart user
New pChart user

Joined: Thu Jan 06, 2011 12:45 pm
Posts: 3
Post Re: Bar Chart bug? with bars too wide
oh thats true, i can just add a dummy for now, eg.

Attachment:
alan2.png
alan2.png [ 20.9 KiB | Viewed 8728 times ]


Thu Jan 06, 2011 3:26 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: Bar Chart bug? with bars too wide
I've forgotten to say that I've fixed it. This will be published in the 2.0.11 subversion.

To fix it now, go in the drawBarChart() function (pDraw class) and modify this two lines :

Code:
if ( $XDivs == 0 ) { $XSize = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XSize   = ($XStep / ($SeriesCount+$Interleave) ); }

by
Code:
if ( $XDivs == 0 ) { $XSize = ($this->GraphAreaX2-$this->GraphAreaX1)/($SeriesCount+$Interleave); } else { $XSize   = ($XStep / ($SeriesCount+$Interleave) ); }


and

Code:
if ( $XDivs == 0 ) { $YSize = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YSize   = ($YStep / ($SeriesCount+$Interleave) ); }

by
Code:
if ( $XDivs == 0 ) { $YSize = ($this->GraphAreaY2-$this->GraphAreaY1)/($SeriesCount+$Interleave); } else { $YSize   = ($YStep / ($SeriesCount+$Interleave) ); }


Kind regards,
JD.


Thu Jan 06, 2011 3:56 pm
Profile WWW
New pChart user
New pChart user

Joined: Thu Jan 06, 2011 12:45 pm
Posts: 3
Post Re: Bar Chart bug? with bars too wide
worked perfectly - thank you and thanks for your quick replies!


Thu Jan 06, 2011 4:20 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: Bar Chart bug? with bars too wide
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


Fri Jan 07, 2011 3:55 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: Google [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron