Contents
Login Register Wishes Forum About
Language Reference » Stock charts » drawStockChart
Help topics
Latest updates
1139d  replaceImageMapTitle
1139d  replaceImageMapValues
1139d  createFunctionSerie
1139d  setAbsicssaPosition
1139d  negateValues
Toolbox
  Download as PDF
  Print this page
  Share this page
  Create an account
  Feed the updates!
Google AdSense
drawStockChart - Draw a stock chart

Require pChart 2.0.11

This function allows you to draw a stock chart. All the drawing parameters are given trough a $Format array. To learn more about this please read the Format array guide.
Calling this function
drawStockChart($Format);
Where :

Format is an array containing the drawing parameters of the chart.

Customisation array - Tune up your chart!

It is possible to customize the stock 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 the name of the serie containing the "Open" value SerieOpen (default is Open).
You can specify the name of the serie containing the "Close" value SerieClose (default is Close).
You can specify the name of the serie containing the "Max" value SerieMax (default is Max).
You can specify the name of the serie containing the "Min" value SerieMin (default is Min).
You can specify the width of the vertical segment with LineWidth.
You can specify the color of the vertical segment with LineR, LineG, LineB, LineAlpha.
You can specify the extremity segments width with ExtremityWidth.
You can specify the extremity segments length with ExtremityLength.
You can specify the color of the extremity segments with ExtremityR, ExtremityG, ExtremityB, ExtremityAlpha.
You can specify the width of the boxes with BoxWidth.
You can specify the color of the positives boxes with BoxUpR, BoxUpG, BoxUpB, BoxUpAlpha, .
You can specify a surrounding factor for the positives boxes borders BoxUpSurrounding.
You can specify the color of the positives boxes border with BoxUpBorderR, BoxUpBorderG, BoxUpBorderB, BoxUpBorderAlpha .
You can specify the color of the negatives boxes with BoxDownR, BoxDownG, BoxDownB, BoxDownAlpha, .
You can specify a surrounding factor for the negatives boxes borders BoxDownSurrounding.
You can specify the color of the negativesboxes border with BoxDownBorderR, BoxDownBorderG, BoxDownBorderB, BoxDownBorderAlpha.
You can choose to enable shadow computing only on the boxes setting ShadowOnBoxesOnly to TRUE.

Sample script #1


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

 /* Create and populate the pData object */
 $MyData = new pData();  
 $MyData->addPoints(array(35,28,17,27,12,12,20,15,20,28),"Open");
 $MyData->addPoints(array(20,17,25,20,25,23,16,29,26,17),"Close");
 $MyData->addPoints(array(10,11,14,11,9,4,3,7,9,5),"Min");
 $MyData->addPoints(array(37,32,33,29,29,25,22,34,29,31),"Max");
 $MyData->setAxisDisplay(0,AXIS_FORMAT_CURRENCY,"$");

 $MyData->addPoints(array("Dec 13","Dec 14","Dec 15","Dec 16","Dec 17", "Dec 20","Dec 21","Dec 22","Dec 23","Dec 24"),"Time");
 $MyData->setAbscissa("Time");

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

 /* Turn of AAliasing */
 $myPicture->Antialias = FALSE;

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

 /* Set the default font settings */
 $myPicture->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.ttf","FontSize"=>6));

 /* Define the chart area */
 $myPicture->setGraphArea(60,30,650,190);

 /* Draw the scale */
 $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
 $myPicture->drawScale($scaleSettings);

 /* Create the pStock object */
 $mystockChart = new pStock($myPicture,$MyData);

 /* Draw the stock chart */
 $stockSettings = array("BoxUpR"=>255,"BoxUpG"=>255,"BoxUpB"=>255,"BoxDownR"=>0,"BoxDownG"=>0,"BoxDownB"=>0);
 $mystockChart->drawStockChart($stockSettings);

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

Sample script #2


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

 /* Create and populate the pData object */
 $MyData = new pData();  
 $MyData->addPoints(array(34,55,15,62,38,42),"Open");
 $MyData->addPoints(array(42,25,40,38,49,36),"Close");
 $MyData->addPoints(array(27,14,12,25,32,32),"Min");
 $MyData->addPoints(array(45,59,47,65,64,48),"Max");
 $MyData->setAxisDisplay(0,AXIS_FORMAT_CURRENCY,"$");
 $MyData->addPoints(array("8h","10h","12h","14h","16h","18h"),"Time");
 $MyData->setAbscissa("Time");

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

 /* Draw the background */
 $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
 $myPicture->drawFilledRectangle(0,0,700,230,$Settings);

 /* Overlay with a gradient */
 $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
 $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);

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

 /* Write the title */
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));
 $myPicture->drawText(60,45,"Stock price",array("FontSize"=>28,"Align"=>TEXT_ALIGN_BOTTOMLEFT));

 /* Draw the 1st scale */
 $myPicture->setGraphArea(60,60,450,190);
 $myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
 $myPicture->drawScale(array("DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE));

 /* Draw the 1st stock chart */
 $mystockChart = new pStock($myPicture,$MyData);
 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
 $mystockChart->drawStockChart();

 /* Reset the display mode because of the graph small size */
 $MyData->setAxisDisplay(0,AXIS_FORMAT_DEFAULT);

 /* Draw the 2nd scale */
 $myPicture->setShadow(FALSE);
 $myPicture->setGraphArea(500,60,670,190);
 $myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
 $myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE));

 /* Draw the 2nd stock chart */
 $mystockChart = new pStock($myPicture,$MyData);
 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
 $mystockChart->drawStockChart();

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("pictures/example.drawStockChart.png");
Last updated on 01/07/2011 
by Jean-Damien 
Linked resources
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 55 comments. 799 users have registered. This page has been rendered in 0,04 seconds. Wiki revision 1.37.