function generateImage($content = '', $store_id = null) { $graph = false; if ($content) { $graph = $content; } elseif (isset($_REQUEST['content'])) { $graph = $_REQUEST['content']; } if (!$graph) { return false; } $script_path = $this->config->item('file_root') . 'js/phantomjs/'; $script_name = 'svg.js'; $image = uniqid('graph_') . '.png'; $path = $this->config->item('csv_upload_path'); $cmd = "phantomjs " . $script_path . $script_name . " " . $path . $image . " '" . $graph . "'"; $ex = exec($cmd); $subfolder = isset($store_id) ? $store_id : ''; return upload_to_amazon_graphImage($image, $path, $subfolder); }
/** * Save the graph data in the database so that phantomjs can use it * to create an image. * * @param array $data * @return String */ protected function generateImageThroughPhantomJS($data) { $enc_data = $this->db->escape(json_encode($data)); $qStr = "insert into " . $this->_table_cron_graph_data . " set\n id = " . $this->data->report_id . ",\n data = " . $enc_data . "\n ON DUPLICATE KEY update\n data = " . $enc_data . "\n "; $this->db->query($qStr); $script_path = $this->config->item('phantomjs'); $script_name = 'rasterize_graph.js'; $image = uniqid('graph_') . '.png'; $path = $this->config->item('csv_upload_path'); $url = site_url("schedule_cron/render_graph/" . $this->data->report_id); $cmd = 'phantomjs ' . $script_path . $script_name . ' "' . $url . '" ' . $path . $image; exec($cmd); return upload_to_amazon_graphImage($image, $path, $this->report_info->store_id); }
function generateGraphImage($finalData = array(), $hourflag, $title = 'Sticky Charts', $x_axis_format = 'date') { $path = $this->config->item('csv_upload_path'); if (isset($finalData['data']) && count($finalData['data']) > 0) { $DataSet = new pData(); $in = 0; foreach ($finalData['data'] as $seriesData) { $in++; $seriesIndex = 'Serie' . $in; $DataSet->AddPoint($seriesData['data'], $seriesIndex); $DataSet->SetSerieName($seriesData['name'], $seriesIndex); $DataSet->AddSerie($seriesIndex); //$DataSet->AddPoint(array(23,432,43,153,234),"Serie2"); } $xAxisArray = array(); $in++; $seriesIndex = 'Serie' . $in; $catCount = count($finalData['cat']); if ($catCount <= 10) { $DataSet->SetXAxisFormat($x_axis_format); } foreach ($finalData['cat'] as $catD) { if ($catCount > 10) { $xAxisArray[] = ''; } else { $xAxisArray[] = strtotime($catD); } } $DataSet->SetYAxisFormat("number"); $DataSet->AddPoint($xAxisArray, $seriesIndex); $DataSet->SetAbsciseLabelSerie($seriesIndex); $DataSet->SetYAxisName($finalData['y_title']); $DataSet->SetXAxisName($finalData['x_title']); // Initialise the graph $Test = new pChart(985, 458); $Test->drawBackground(247, 226, 180); $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8); $Test->setGraphArea(40, 30, 950, 400); $Test->drawGraphArea(109, 110, 114, false); $Test->drawGrid(4, false, 0, 0, 0, 50); // Draw the 0 line $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 6); // Draw the line graph $sCount = count($finalData['data']); if ($sCount > 0) { for ($m = 0; $m < $sCount; $m++) { $color = Color_handler::get_next($m); $rgb = $color->get_rgb(); $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']); } } $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 0, 0, 0, TRUE, 0, 0, TRUE); $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription()); // Finish the graph $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8); $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 10); $imgName = uniqid('graph_') . '.png'; $Test->Render($path . $imgName); return upload_to_amazon_graphImage($imgName, $path); } }