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());
$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();
/** * 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(); }