Thursday, February 6, 2014

Mgento 1.2 How we can implement Graphical Chart result in php!

Easy Sample code to implement:
 four type of graph given with Variables are User defined!
<?php
require ('gChart.php');
ini_set('display_errors','1');
 $type = $_POST["type"];
 $var1 = $_POST["var1"];
 $var2 = $_POST["var2"];
 $var4 = $_POST["var4"];
 $var3 = $_POST["var3"];
?>
<?php
ini_set('display_errors','1');
?>
<html>
<head>
<title>Test</title>

<style type="text/css">
img { display:block; }
</style>
</head>
<body>
<h1>Sample charts</h1>
<h1>Quick examples.</h1>
<table align="center">
<tr>
<td>
<h2>Pie Chart</h2> // Type1
<?php
$piChart = new gPieChart();
$piChart->addDataSet(array($var1,$var2,$var3,$var4));
$piChart->setLegend(array("first", "second", "third","fourth"));
$piChart->setLabels(array("first", "second", "third","fourth"));
$piChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
?>
<img src="<?php print $piChart->getUrl();  ?>" /> <br> Simple chart .
</td>
<td>
<h2>3D Pie Chart</h2> type2
<?php
$pie3dChart = new gPie3DChart();
$pie3dChart->addDataSet(array($var1,$var2,$var3,$var4));
$pie3dChart->setLegend(array("first", "second", "third","fourth"));
$pie3dChart->setLabels(array("first", "second", "third","fourth"));
$pie3dChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
?>
<img src="<?php print $pie3dChart->getUrl();  ?>" /> <br> 3D Simple Chart.
</td>
</tr>
<tr>
<td>
<h2>Grouped Bar Chart</h2> type3
<?php
$barChart = new gBarChart(250,250,'s');
$barChart->addDataSet(array(0,10,20,30,20,70,80));
$barChart->addDataSet(array(0,20,10,5,20,30,10));
$barChart->addHiddenDataSet(array(10,0,20,15,60,40,30));
$barChart->addValueMarkers('D','76A4FB',2,0,3);
$barChart->setAutoBarWidth();
?>
<img src="<?php print $barChart->getUrl();  ?>" /> <br> compound bar chart using the gGroupedBarChart class and addValueMarkers().
</td>
<td>
<h2>Line Chart with Grid Lines</h2> type4
<?php
$lineChart = new gLineChart(300,300);
$lineChart->addDataSet(array($var1,$var2,$var3,$var4));
$lineChart->addDataSet(array(212,115,366,140));
$lineChart->addDataSet(array(112,95,116,140));
$lineChart->setLegend(array("first", "second", "third","fourth"));
$lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
$lineChart->setVisibleAxes(array('x','y'));
$lineChart->setDataRange(0,400);
$lineChart->addAxisRange(0, 1, 4, 1);
$lineChart->addAxisRange(1, 0, 400);
$lineChart->setGridLines(33,10);
?>
<img src="<?php print $lineChart->getUrl();  ?>" /> <br> line chart using the gLineChart class.
</td>
</tr>
</table>
</body>
</html>

No comments:

Post a Comment