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

Bar Chart bug? with bars too wide
http://wiki.pchart.net/forum/viewtopic.php?f=1&t=52
Page 1 of 1

Author:  digi_al [ Thu Jan 06, 2011 12:53 pm ]
Post subject:  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 9705 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"  />

Author:  jean-damien [ Thu Jan 06, 2011 2:13 pm ]
Post subject:  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.

Author:  digi_al [ Thu Jan 06, 2011 3:26 pm ]
Post subject:  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 9699 times ]

Author:  jean-damien [ Thu Jan 06, 2011 3:56 pm ]
Post subject:  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.

Author:  digi_al [ Thu Jan 06, 2011 4:20 pm ]
Post subject:  Re: Bar Chart bug? with bars too wide

worked perfectly - thank you and thanks for your quick replies!

Author:  jean-damien [ Fri Jan 07, 2011 3:55 pm ]
Post subject:  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

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