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; }
public function getGraphData() { $company = Input::get('company'); $interval = Input::get('interval'); $precision = Input::get('prc'); $company_symbol = isset($company) && !empty($company) ? $company : 'goog'; $interval = isset($interval) && !empty($interval) ? $interval : 'd'; $precision = isset($precision) && !empty($precision) && is_numeric($precision) ? $precision : 1; $stock_market = new StockMarket($company_symbol, $interval, $precision); //<---class declared here and passed the datas /* // <--utilizing the function for finding the Company name from Symbol //<-- to check the given company symbol is correct or not */ $company_name = $stock_market->find_company_name_from_symbol(); if ($company_name) { //<-- if company name given is not false go further $stock_records = $stock_market->get_the_market_data(); //<--function to collect Historical data for given company symbol if ($stock_records) { //<----if it retuns a record then proceed $range_from = $stock_market->get_graph_range_start(); //<--this function helps to calculate historical Graph area minmum range $range_to = $stock_market->get_graph_range_ends(); //<--this function helps to calculate historical Graph area maximum range $lower_range_coords = $stock_market->get_lower_price_data(); //<--this function helps to return the lower price data for graph $higher_range_coords = $stock_market->get_higher_price_data(); //<--this function helps to return the higher price data for graph $graph = new PHPGraphLib(470, 270); $graph->addData($lower_range_coords); $graph->addData($higher_range_coords); $graph->setRange($range_from, $range_to); $graph->setTitle($company_name . ' Graph'); $graph->setBars(false); $graph->setLine(true); $graph->setDataPoints(true); $graph->setDataPointColor('maroon'); $graph->setDataPointColor('red'); $graph->setDataValues(true); $graph->setDataValueColor('blue'); $graph->setGoalLine(0.25); $graph->setGoalLineColor('red'); $graph->createGraph(); //<--this draw the graph $contents = View::make('graph')->with('graph', $graph); // Create a response and modify a header value $response = Response::make($contents, 200); $response->header('Content-Type', 'image/png'); return $response; } //<-- stock data checks ends } //<--company name check ends }
function create_graph($graph_type = '') { $graph = new PHPGraphLib(1400, 600); $model = new TwextraModel(); //$data = array("Alex"=>99, "Mary"=>98, "Joan"=>70, "Ed"=>90); if ($graph_type == 'daily_stats') { $data = $model->get_stats_daily(); $graph->setTitle("Daily Unique Traffic"); } else { if ($graph_type == 'message_history') { //this graph is currently not plotted! $screen_name = 'rajen4126'; $message_from = 0; $next = 20; $order = 'created'; $asc_desc = 'desc'; $length = 20; $data = $model->get_message_history($screen_name, $message_from, $next, $order, $asc_desc, $length); foreach ($data as $entry) { $data[$entry[message_id]] = $entry[view_count]; } $graph->setTitle("Message History"); } else { if ($graph_type == 'monthly_stats') { $data = $model->get_monthly_uniques(); $graph->setTitle("Monthly Unique Traffic"); } else { if ($graph_type == 'messages_stats') { $data = $model->get_messages_stats(); $graph->setTitle("Daily Messages Created"); } else { $data = array(); } } } } $graph->addData($data); $graph->setTextColor("blue"); //additions for a line graph.......... $graph->setBars(false); $graph->setLine(true); //$graph->setDataPoints(true); $graph->setDataPointColor('maroon'); $graph->setDataValues(true); $graph->setDataValueColor('maroon'); $graph->setGoalLine(0.0025); $graph->setGoalLineColor('red'); //........ return $graph->createGraph(); }
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(); }
public function gbarra_getImagen($titulo = " ", $width = "500", $height = "350") { $config = XTConfig::singleton(); $data = $this->barra_data; $nombreimagen = uniqid() . "barraimagen.png"; $file = $config->get("XTSITE_PATH_ABSOLUTE") . "tmp/pie/" . $nombreimagen; $file_url = $config->get("XTSITE_PATH") . "tmp/pie/" . $nombreimagen; $graph = new PHPGraphLib($width, $height, $file); $graph->addData($data); //$graph->setBarColor('255,255,204'); $graph->setGradient('255,255,204', '254,254,154'); if ($titulo != "") { $graph->setTitle($titulo); } $graph->setLineColor('maroon'); $graph->setDataPointColor('maroon'); $graph->setXValuesHorizontal(true); $graph->setLine(true); $graph->setDataPoints(true); $graph->setDataValues(true); $graph->createGraph(); print "<img src=\"{$file_url}\">"; }
<?php include '../phpgraphlib.php'; $graph = new PHPGraphLib(350, 280); $data = array("Roger" => 145, "Ralph" => 102, "Rhonda" => 123, "Ronaldo" => 137, "Rosario" => 149, "Robin" => 99, "Robert" => 88, "Rustof" => 111); $graph->setBackgroundColor("black"); $graph->addData($data); $graph->setBarColor('255, 255, 204'); $graph->setTitle('IQ Scores'); $graph->setTitleColor('yellow'); $graph->setupYAxis(12, 'yellow'); $graph->setupXAxis(20, 'yellow'); $graph->setGrid(false); $graph->setGradient('silver', 'gray'); $graph->setBarOutlineColor('white'); $graph->setTextColor('white'); $graph->setDataPoints(true); $graph->setDataPointColor('yellow'); $graph->setLine(true); $graph->setLineColor('yellow'); $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(); }