function xls_write_graph($graphfile = null) { //init all $CI =& get_instance(); //load $CI->load->helper('misc'); $graph = new PHPGraphLib(495, 280, $graphfile); $data1 = array('alpha' => intval(rand(20) + 1), 'beta' => intval(rand(15) + 1), 'cappa' => intval(rand(10) + 1), 'delta' => intval(rand(20) + 1), 'echo' => intval(rand(10) + 1)); $data2 = array('alpha' => intval(rand(8) + 1), 'beta' => intval(rand(20) + 1), 'cappa' => intval(rand(20) + 1), 'delta' => intval(rand(20) + 1), 'echo' => intval(rand(50) + 1)); $data3 = array('alpha' => intval(rand(25) + 1), 'beta' => intval(rand(8) + 1), 'cappa' => intval(rand(10) + 1), 'delta' => intval(rand(50) + 1), 'echo' => intval(rand(50) + 1)); $data4 = array('alpha' => intval(rand(7) + 1), 'beta' => intval(rand(50) + 1), 'cappa' => intval(rand(5) + 1), 'delta' => intval(rand(50) + 1), 'echo' => intval(rand(50) + 1)); $data = array(rand(20, 30), rand(40, 50), 20, 44, 41, 18, rand(40, 50), 19, rand(40, 50)); $data2 = array(15, rand(20, 30), rand(20, 30), 11, rand(40, 60), 21, rand(40, 60), 34, rand(20, 30)); $data3 = array(rand(40, 50), rand(20, 30), 34, 23, rand(45, 60), 32, 43, 41); $graph->addData($data, $data2, $data3); $graph->setTitle('CPU Cycles x1000'); $graph->setTitleLocation('left'); $graph->setLegend(true); $graph->setLegendTitle('Module-1', 'Module-2', 'Module-3'); $xcolor1 = sprintf("%02X%02X%02X", rand(20, 255), rand(20, 250), rand(20, 250)); $xcolor2 = sprintf("%02X%02X%02X", rand(20, 250), rand(20, 255), rand(20, 250)); $graph->setGradient("#{$xcolor1}", "#{$xcolor2}"); $graph->createGraph(); //give the format return 1; }
function make_graph_multi_line($title, $data_min, $data_avg, $data_max, $is_bar_graph) { include 'phpgraphlib.php'; $graph = new PHPGraphLib(780, 300); if ($is_bar_graph == 'true') { $graph->setBars(true); $graph->setLine(false); } else { $graph->setBars(false); $graph->setLine(true); } $graph->setDataPoints(true); $graph->setDataPointSize(4); $graph->setDataPointColor('purple'); $graph->setLegend(true); if (!isset($data_min)) { $graph->addData($data_avg); $graph->addData($data_max); if ($is_bar_graph == 'true') { $graph->setBarColor('purple', 'red'); } else { $graph->setLineColor('purple', 'red'); } $graph->setLegendTitle('avg', 'max'); } else { $graph->addData($data_min); $graph->addData($data_avg); $graph->addData($data_max); if ($is_bar_graph == 'true') { $graph->setBarColor('blue', 'purple', 'red'); } else { $graph->setLineColor('blue', 'purple', 'red'); } $graph->setLegendTitle('min', 'avg', 'max'); } $graph->setTitle($title); $graph->setTitleColor("88,89,91"); $graph->setXValuesVertical(true); $graph->createGraph(); }
<?php session_start(); require_once "../Includes.php"; //print("<img src=\"../Utilities/Charts.php?chart=padaliniu_paraiskos&menuo=2008-01-01\">"); $graph = new PHPGraphLib(650, 200); $data1 = array(0); $data2 = array(8, 15, 4, 12); $data3 = array(1, 2, 3, 4); $graph->addData($data2); $graph->setTitle('PPM Per Container'); $graph->setBars(false); $graph->setLine(true); $graph->setLineColor('#FF0000', 'green', 'red'); $graph->setDataPoints(true); $graph->setDataPointColor('maroon'); $graph->setDataValues(true); $graph->setDataValueColor('maroon'); $graph->setLegend(true); $graph->setLegendTitle("PA1", "PA2", "PA3"); $graph->createGraph(); p(ErrorMessages::getErrors());
<?php include '../phpgraphlib.php'; $graph = new PHPGraphLib(500, 280); $data = array(23, 45, 20, 44, 41, 18, 49, 19, 42); $data2 = array(15, 23, 23, 11, 54, 21, 56, 34, 23); $data3 = array(43, 23, 34, 23, 53, 32, 43, 41); $graph->addData($data, $data2, $data3); $graph->setTitle('CPU Cycles x1000'); $graph->setTitleLocation('left'); $graph->setLegend(true); $graph->setLegendTitle('Module-1', 'Module-2', 'Module-3'); $graph->setGradient('green', 'olive'); $graph->createGraph();
<?php require_once dirname(__FILE__) . '\\..\\util.php'; require_abs('images/graphs/phpgraphlib.php'); require_abs('images/graphs/phpgraphlib_pie.php'); require_controller('statisticsGraphicsController'); use Qnet\Controller\StatisticsGraphicsController; $sid = $_GET['sid']; $ctrl = new StatisticsGraphicsController(); $ctrl->computeStatistic($sid); if (!$ctrl->isDrawable()) { echo 'Cannot draw this statistic.'; } else { $big = $_GET['size'] == 'big'; $graph = new PHPGraphLib($big ? 800 : 400, $big ? 400 : 200); $graph->addData($ctrl->getData(0), $ctrl->getData(1), $ctrl->getData(2), $ctrl->getData(3), $ctrl->getData(4)); if ($ctrl->hasZ()) { $graph->setLegend(true); $graph->setLegendTitle($ctrl->getLegend(0), $ctrl->getLegend(1), $ctrl->getLegend(2), $ctrl->getLegend(3), $ctrl->getLegend(4)); } $graph->setXValuesHorizontal(true); $graph->createGraph(); }
<?php include '../phpgraphlib.php'; $graph = new PHPGraphLib(495, 280); $data = array('alpha' => 23, 'beta' => 45, 'cappa' => 20, 'delta' => 32, 'echo' => 14); $data2 = array('alpha' => 15, 'beta' => 23, 'cappa' => 23, 'delta' => 12, 'echo' => 17); $data3 = array('alpha' => 43, 'beta' => 23, 'cappa' => 34, 'delta' => 16, 'echo' => 20); $data4 = array('alpha' => 23, 'beta' => 34, 'cappa' => 23, 'delta' => 9, 'echo' => 8); $graph->addData($data, $data2, $data3, $data4); $graph->setupYAxis("15"); $graph->setGradient('teal', '#0000FF'); $graph->setXValuesHorizontal(true); $graph->setXAxisTextColor('navy'); $graph->setLegend(true); $graph->setLegendTitle('M1', 'M2', 'M3', 'M4'); $graph->createGraph();
$all = array(array()); $sql = "SELECT LB, remote_ID, name, amount, transdate FROM firsttable"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { if ($row['remote_ID'] == $_SESSION['handle']) { if ($row['name'] == $_SESSION["graphval"]) { if ($row['LB'] == 'L') { if (array_key_exists($row['transdate'], $lenddata)) { $lenddata[$row['transdate']] = $lenddata[$row['transdate']] + $row['amount']; } else { $lenddata[$row['transdate']] = $row['amount']; } } else { if (array_key_exists($row['transdate'], $borrowdata)) { $borrowdata[$row['transdate']] = $borrowdata[$row['transdate']] + $row['amount']; } else { $borrowdata[$row['transdate']] = $row['amount']; } } } } } } $graph->addData($lenddata, $borrowdata); $graph->setXValuesHorizontal(TRUE); $graph->setTextColor('blue'); $graph->setBarColor('green', 'red'); $graph->setLegend(TRUE); $graph->setLegendTitle('Lended', 'Borrowed'); $graph->createGraph();
<?php include '../phpgraphlib.php'; $set1 = array(1917 => 4011, 1918 => 4886, 1919 => 5411, 1920 => 5831, 1921 => 5865, 1922 => 5704, 1923 => 5337, 1924 => 5144, 1925 => 5018, 1926 => 4971, 1927 => 4630, 1928 => 4411, 1929 => 4287, 1930 => 4116, 1931 => 3940, 1932 => 3764, 1933 => 3592, 1934 => 3447, 1935 => 3280, 1936 => 3215, 1937 => 3366, 1938 => 3569, 1939 => 3598, 1940 => 4436, 1941 => 5939, 1942 => 7397, 1943 => 8855, 1944 => 9835, 1945 => 9998, 1946 => 10631, 1947 => 11340, 1948 => 11549, 1949 => 11642); $set2 = array(1910 => 2059, 1911 => 2135, 1912 => 2209, 1913 => 2332, 1914 => 2437, 1915 => 2786, 1916 => 3747, 1917 => 5011, 1918 => 5886, 1919 => 6411, 1920 => 6831, 1921 => 6865, 1922 => 6704, 1923 => 6337, 1924 => 6144, 1925 => 6018, 1926 => 5971, 1927 => 5630, 1928 => 5411, 1929 => 5287, 1930 => 5116, 1931 => 4940, 1932 => 4764, 1933 => 4592, 1934 => 4447, 1935 => 4280, 1936 => 4215, 1937 => 4366, 1938 => 4569, 1939 => 4598, 1940 => 5436, 1941 => 5939, 1942 => 8397, 1943 => 9855, 1944 => 10835); $graph = new PHPGraphLib(600, 400); $graph->addData($set1, $set2); $graph->setTitleLocation('left'); $graph->setTitle("Two sets with different start points"); $graph->setBars(false); $graph->setLine(true); $graph->setDataPoints(false); $graph->setLineColor('blue', 'red'); $graph->setDataValues(false); $graph->setXValuesInterval(5); $graph->setDataValueColor('blue', 'red'); $graph->setLegend(true); $graph->setLegendTitle("set1", "set2"); $graph->createGraph();
$sql = "SELECT `ip` FROM `conf_leases` WHERE `ip` LIKE \"" . $match[1] . ".%\""; // execute query and place results (if any) in array per-subnet if (($value = $db->dbQuery($val->ValidateSQL($sql, $dbconn), $dbconn)) !== -1) { $all[$name] = $total; $data[$name] = count($db->dbArrayResults($value)); } } } // generate our graphs but check for gd lib extensions first if (function_exists('imagedestroy')) { $graph = new PHPGraphLib(450, 200); // push the image and assign attributes $graph->addData($data, $all); $graph->setTitle("Total Leases: " . $total_leases); $graph->setTitleLocation("left"); $graph->setLegendTitle("Available", "In Use"); $graph->setBars(true); $graph->setLegend(true); $graph->setDataPoints(true); $graph->setDataPointColor("red"); $graph->setDataValueColor("gray"); $graph->createGraph(); } } else { // page view restricted by access level $ERROR = $err->GenerateErrorLink("help/help.html", "#undef", $defined['error'], $errors['level']); } } else { // general authentication error $ERROR = $err->GenerateErrorLink("help/help.html", "#undef", $defined['error'], $errors['auth_n']); }
<?php include '../phpgraphlib.php'; $graph = new PHPGraphLib(520, 280); $data = array("Alpha" => 1145, "Beta" => 1202, "Cappa" => 1523, "Delta" => 1437, "Echo" => 949, "Falcon" => 999, "Gamma" => 1188); $data2 = array("Alpha" => 898, "Beta" => 1498, "Cappa" => 1343, "Delta" => 1345, "Echo" => 1045, "Falcon" => 1343, "Gamma" => 987); $graph->addData($data, $data2); $graph->setBarColor('blue', 'green'); $graph->setTitle('Company Production'); $graph->setupYAxis(12, 'blue'); $graph->setupXAxis(20); $graph->setGrid(false); $graph->setLegend(true); $graph->setTitleLocation('left'); $graph->setTitleColor('blue'); $graph->setLegendOutlineColor('white'); $graph->setLegendTitle('Week-37', 'Week-38'); $graph->setXValuesHorizontal(true); $graph->createGraph();
<?php if ($_REQUEST['mode'] == 'graph' || $_REQUEST['mode'] == 'graph_line') { include '../lib/phpgraphlib.php'; $graph = new PHPGraphLib(1120, 600); $graph->addData(unserialize($_REQUEST['graph_data'])); if ($_REQUEST['mode'] == 'graph_line') { $graph->setBars(false); $graph->setLine(true); $graph->setLineColor(); } else { $graph->setGradient(); } $graph->setLegend(true); $graph->setLegendTitle(unserialize($_REQUEST['titles'])); $graph->createGraph(); } elseif ($_REQUEST['mode'] == 'graph_pie') { include '../lib/phpgraphlib.php'; include '../lib/phpgraphlib_pie.php'; $graph = new PHPGraphLibPie(1120, 600); $graph->addData(unserialize($_REQUEST['graph_data'])); $graph->setLabelTextColor("50,50,50"); $graph->createGraph(); }
} // process last 6 hour traffic array foreach ($traffic_old as $key_old => $value_old) { if ($value_old['interface'] !== 'lo') { $value_old['bytes'] = $value_old['bytes'] / 1024 / 1024; $old[$value_old['interface']] = round($value_old['bytes']); $total_old = round($total_old + $value_old['bytes']); } } // get total from both data sets $total = $total_new + $total_old; // push the image and assign attributes $graph->addData($old, $recent); $graph->setTitle("MBytes Total: " . $total); $graph->setTitleLocation("left"); $graph->setLegendTitle("Last 60 Minutes", "Last 6 Hours"); $graph->setBars(true); $graph->setLegend(true); $graph->setDataPoints(true); $graph->setDataPointColor("red"); $graph->setDataValueColor("gray"); $graph->setGoalLineColor("red"); $graph->createGraph(); } } else { // page view restricted by access level $ERROR = $err->GenerateErrorLink("help/help.html", "#undef", $defined['error'], $errors['level']); } } else { // general authentication error $ERROR = $err->GenerateErrorLink("help/help.html", "#undef", $defined['error'], $errors['auth_n']);
/** * Function to generate a file containing a graph of power (kW) against * solar radiation (W/m2) using data from the given tables. A date range * can be specified to restrict the x-axis. * @param string $imageFilename Name of file to write graph to * @param string $powerTable Name of table to get power data from * @param string $solRadTable Name of table to get solar radiation data from * @param array $dateRange An optional array of two DateTime objects to limit * the range of data used */ public function createGraphImage($imageFilename, $powerTable, $powerColumn, $solRadTable, &$dateRange = NULL) { global $verbose; if (!$this->graphsEnabled) { return; } // We inner join the tables on the datetime field. This is expected to be called on // a solar radiation data table and a instananeous power data table so the two can // be easily compared. They will need different y-axes. if ($verbose > 0) { print "Generating power graph in file {$imageFilename}\n"; } $sql = "SELECT {$powerTable}.datetime, {$powerTable}.{$powerColumn}, sol_rad\n FROM {$solRadTable} INNER JOIN {$powerTable}\n ON {$powerTable}.datetime = {$solRadTable}.datetime"; $whereClause = ''; $whereClausePower = ''; if ($dateRange != NULL) { $whereClause = " WHERE DATE({$solRadTable}.datetime) > '" . $dateRange[0]->format('Y-m-d') . "' &&\n DATE({$solRadTable}.datetime) < '" . $dateRange[1]->format('Y-m-d') . "'"; $whereClausePower = str_replace($solRadTable, $powerTable, $whereClause); } $sql .= $whereClause; $data = $this->fetchQuery($sql); $maxSolRad = $this->fetchQuery("SELECT MAX(sol_rad) FROM {$solRadTable}" . $whereClause, PDO::FETCH_NUM); $maxPower = $this->fetchQuery("SELECT MAX({$powerColumn}) FROM {$powerTable}" . $whereClausePower, PDO::FETCH_NUM); if ($maxPower[0][0] == 0) { // If there was never any power, divide by 1 rather than 0 when scaling! $maxPower[0][0] = 1; } $graph = new PHPGraphLib(10000, 1000, $imageFilename); $graph->setTitle($powerTable . ' against solar radiation (both scaled to % of maximum recorded value)'); $graph->setBars(FALSE); $graph->setLine(TRUE); $graph->setLineColor('red', 'yellow'); $graph->setLegend(TRUE); $graph->setLegendTitle('Power', 'Solar radiation'); // Reassmble the data into the form needed for PHPGraphLib and scale values so they can be plotted on the same // y-axis (a limitation of PHPGraphLib...if we can go GPLv3, we can use PCharts2 which can do multiple y-axes, // or there's SVGGraph which is LGPL). foreach ($data as $entry) { $powerData[$entry['datetime']] = $entry[$powerColumn] / $maxPower[0][0] * 100; $solRadData[$entry['datetime']] = $entry['sol_rad'] / $maxSolRad[0][0] * 100; } // Free up memory (maybe!) $data = NULL; $graph->addData($powerData, $solRadData); $graph->createGraph(); }