Example #26 - Playing with shadows and second Y axis
Since release 1.27d it is possible to draw shadows behind drawn pixels. Shadow can be added to any plot-drawn objects
line lines and cubics. Use shadows with caution as this will add extra computing time to your charts. If you want to
display rendered data on your web pages, I invite you to use the pCache class to speed up the processing time.
This example is showing how to display two data series with dedicated Y axis. Basic way to associate a data serie
to one axis is to first add only the attached data series to the grapher using the
AddSerie() function of the pData class
and then invoke the
drawScale() function of the pChart class.
Before drawing the right scale, use the
clearScale() function and remove the previously
graphed series with the
RemoveSerie() function of the pData class. Then add
the remaining series using the
AddSerie() function and compute the second Y axis
calling the
drawRightScale() function.
Shadows are activated calling the
setShadowProperties() function. You must
remove the shadow engine calling the
clearShadow() when you've finished to
draw your data series. If you forget to remove the shadow, you'll experience strange graphing effects.
Running this script will create a
example26.png file in the current directory.
Output :
Source code :
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");
// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(110,101,118,108,110,106,104),"Serie1");
$DataSet->AddPoint(array(700,2705,2041,1712,2051,846,903),"Serie2");
$DataSet->AddPoint(array("03 Oct","02 Oct","01 Oct","30 Sep","29 Sep","28 Sep","27 Sep"),"Serie3");
$DataSet->AddSerie("Serie1");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("SourceForge Rank","Serie1");
$DataSet->SetSerieName("Web Hits","Serie2");
// Initialise the graph
$Test = new pChart(660,230);
$Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND);
// Prepare the graph area
$Test->setFontProperties("fonts/tahoma.ttf",8);
$Test->setGraphArea(60,40,595,190);
// Initialise graph area
$Test->setFontProperties("fonts/tahoma.ttf",8);
// Draw the SourceForge Rank graph
$DataSet->SetYAxisName("Sourceforge Rank");
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0);
$Test->drawGraphAreaGradient(40,40,40,-50);
$Test->drawGrid(4,TRUE,230,230,230,10);
$Test->setShadowProperties(3,3,0,0,0,30,4);
$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->clearShadow();
$Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,30);
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
// Clear the scale
$Test->clearScale();
// Draw the 2nd graph
$DataSet->RemoveSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetYAxisName("Web Hits");
$Test->drawRightScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0);
$Test->drawGrid(4,TRUE,230,230,230,10);
$Test->setShadowProperties(3,3,0,0,0,30,4);
$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->clearShadow();
$Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,30);
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
// Write the legend (box less)
$Test->setFontProperties("fonts/tahoma.ttf",8);
$Test->drawLegend(530,5,$DataSet->GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE);
// Write the title
$Test->setFontProperties("fonts/MankSans.ttf",18);
$Test->setShadowProperties(1,1,0,0,0);
$Test->drawTitle(0,0,"SourceForge ranking summary",255,255,255,660,30,TRUE);
$Test->clearShadow();
// Render the picture
$Test->Render("example26.png");
?>
|
|
If you want to send the picture directly in a browser, replace the Render() command by Stroke(). |
|
|
Last updated on 10/03/2008 |