#native_company# #native_desc#
#native_cta#

RChart Php Edition

By Jaume
on March 5, 2004

Version: 1.0

Type: Sample Code (HOWTO)

Category: Graphics

License: Other

Description: This example shows how to create a chart using RChart Php edition. The example creates a combination of line and barchart with 2 Y axis (left and right).

The complete RChart package can be found here:

http://www.java4less.com/rchartphp/index.html

// include rchart package
require("chartLoader.inc");
require("Chart.inc");

$g = new ChartGraphics;
$g->create(600,400);

// define variable 
$chartLoader= new ChartLoader(); 

// create parameters for the chart, see: 
// http://www.java4less.com/rchartphp/tutorial/chart/tutorialcontents.html

// configuration of the legend
$chartLoader->setParameter("LEGEND"              ,"TRUE");
$chartLoader->setParameter("LEGEND_POSITION"     ,"BOTTOM");
$chartLoader->setParameter("LEGEND_VERTICAL"     ,"false");
$chartLoader->setParameter("LEGEND_MARGIN"       ,"0.12");
$chartLoader->setParameter("LEGEND_BORDER"       ,"1|BLACK|LINE");

// configuration of labels
$chartLoader->setParameter("YLABEL"              ,"Factor A");
$chartLoader->setParameter("YLABEL_FONT"         ,"Verdana|PLAIN|10");
$chartLoader->setParameter("Y2LABEL_VERTICAL" ,"true");
$chartLoader->setParameter("YLABEL_VERTICAL" ,"true");
$chartLoader->setParameter("Y2LABEL"             ,"Measure");
$chartLoader->setParameter("Y2LABEL_FONT"        ,"Verdana|PLAIN|10");

// configuration of the lines
$chartLoader->setParameter("SERIE_1"             ,"Factor A");
$chartLoader->setParameter("SERIE_FONT_1"        ,"Arial|PLAIN|9");
$chartLoader->setParameter("SERIE_DATA_1"        ,"1396.5|1402.389|1408.278|1414.167|1420.056|425.944|1531.833|1637.722|1743.611|1449.5");
$chartLoader->setParameter("SERIE_STYLE_1","3|#F5B549|LINE");
$chartLoader->setParameter("SERIE_TYPE_1"        ,"LINE");
$chartLoader->setParameter("SERIE_DATAX_1"       ,"1|2|3|4|5|6|7|8|9|10");

// configuration of the bars
$chartLoader->setParameter("SERIE_2"             ,"Measure");
$chartLoader->setParameter("SERIE_DATA_2"        ,"0|0|0|0|300|1000|400|700|0|0");
$chartLoader->setParameter("SERIE_TYPE_2"        ,"BAR");
$chartLoader->setParameter("SERIE_STYLE_2"       ,"#EEEEEE");
$chartLoader->setParameter("SERIE_FONT_2"        ,"Arial|PLAIN|9");
$chartLoader->setParameter("SERIE_COLOR_2"       ,"BLACK");
$chartLoader->setParameter("BARCHART_BARWIDTH"   ,"20");
$chartLoader->setParameter("SERIE_SECONDYAXIS_2" ,"TRUE");

// configuration of the scale and axis
$chartLoader->setParameter("BIG_TICK_INTERVALY"  ,"2");
$chartLoader->setParameter("TICK_INTERVALY"      ,"244");
$chartLoader->setParameter("YSCALE_MIN"          ,"0");
$chartLoader->setParameter("YSCALE_MAX"          ,"3844");
$chartLoader->setParameter("XSCALE_MAX"          ,"11");
$chartLoader->setParameter("YAXIS_AUTO_TICKS"    ,"true");

$chartLoader->setParameter("XAXIS_GRID"          ,"1|#DDDDDD|LINE");
$chartLoader->setParameter("XAXIS_INITIAL_DATE"  ,"10/10/2003");
$chartLoader->setParameter("XAXIS_DATE_STEP"     ,"d");
$chartLoader->setParameter("XAXIS_DATE_FORMAT"   ,"%d/%m/%y");
$chartLoader->setParameter("XAXIS_TICKATBASE"    ,"false");
$chartLoader->setParameter("BIG_TICK_INTERVALX"  ,"2");
$chartLoader->setParameter("TICK_INTERVALX"  ,"1");
$chartLoader->setParameter("BIG_TICK_INTERVALY2" ,"2");
$chartLoader->setParameter("TICK_INTERVALY2"     ,"95");
$chartLoader->setParameter("Y2SCALE_MIN"         ,"0");
$chartLoader->setParameter("Y2SCALE_MAX"         ,"953");
$chartLoader->setParameter("Y2AXIS"              ,"true");
$chartLoader->setParameter("YAXIS_GRID"          ,"1|#DDDDDD|LINE");

$chartLoader->setParameter("CHART_SECOND_AXIS_MARGIN","0");
$chartLoader->setParameter("CHART_FILL"          ,"#FFFFFF");
$chartLoader->setParameter("CHART_SHOW_POSITION" ,"true");

// create chart 
$chart=& $chartLoader->buildChart();
$chart->setSize(600,400);
$chart->paint($g);
$g->setType("png");
// send image to browser
$g->outputImage(  &$filename );