本文整理汇总了PHP中pChart::loadColorPalette方法的典型用法代码示例。如果您正苦于以下问题:PHP pChart::loadColorPalette方法的具体用法?PHP pChart::loadColorPalette怎么用?PHP pChart::loadColorPalette使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pChart
的用法示例。
在下文中一共展示了pChart::loadColorPalette方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pData
echo $data1 = 0;
echo $data2 = 0;
echo $data3 = 0;
echo $data4 = 0;
echo $data5 = 400;
echo $data6 = 0;
$val = "";
for ($i = 1; $i < 7; $i++) {
}
// Standard inclusions
include "pChart/pData.class";
include "pChart/pChart.class";
// Dataset definition
$DataSet = new pData();
$DataSet->AddPoint(array($data1, $data2, $data3, $data4, $data5, $data6), "Serie1");
$DataSet->AddPoint(array("January", "February", "March", "April", "May", "June"), "Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
// Initialise the graph
$Test = new pChart(300, 200);
$Test->loadColorPalette("Sample/softtones.txt");
$Test->drawFilledRoundedRectangle(7, 7, 293, 193, 5, 240, 240, 240);
$Test->drawRoundedRectangle(5, 5, 295, 195, 5, 230, 230, 230);
// This will draw a shadow under the pie chart
$Test->drawFilledCircle(122, 102, 70, 200, 200, 200);
// Draw the pie chart
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->AntialiasQuality = 0;
$Test->drawBasicPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 120, 100, 70, PIE_PERCENTAGE, 255, 255, 218);
$Test->drawPieLegend(230, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250);
$Test->Render("example14.png");
示例2: array
//.........这里部分代码省略.........
$DataSet = new pData();
// Reverse array, otherwise we get highest values first
$resource = array_reverse($resource, true);
foreach ($resource as $name => $cant) {
$DataSet->AddPoint($cant, "Serie" . $j);
$DataSet->SetSerieName(strip_tags($name), "Serie" . $j);
$j++;
}
//print_r($pre_result); print_r($header_name);
// Dataset definition
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie('');
$DataSet->SetXAxisName(get_lang('GradebookSkillsRanking'));
$DataSet->SetYAxisName(get_lang('Students'));
$show_draw = true;
// Cache definition
$Cache = new pCache();
// the graph id
$gradebook_id = intval($_GET['selectcat']);
$graph_id = api_get_user_id() . 'ByResource' . $gradebook_id . api_get_course_id() . api_get_session_id();
if ($show_draw) {
//if ($Cache->IsInCache($graph_id, $DataSet->GetData())) {
if (0) {
//if we already created the img we get the img file id
//echo 'in cache';
$img_file = $Cache->GetHash($graph_id, $DataSet->GetData());
} else {
// if the image does not exist in the archive/ folder
// Initialise the graph
$chart_size_w = 480;
$chart_size_h = 250;
$Test = new pChart($chart_size_w, $chart_size_h);
// Adding the color schemma
$Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/pastel.txt");
// set font of the axes
$Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8);
$area_graph_w = $chart_size_w - 130;
$Test->setGraphArea(50, 30, $area_graph_w, $chart_size_h - 50);
$Test->drawFilledRoundedRectangle(5, 5, $chart_size_w - 1, $chart_size_h - 20, 5, 240, 240, 240);
//$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230);
//background color area & stripe or not
$Test->drawGraphArea(255, 255, 255, TRUE);
//Setting max height by default see #3296
if (!empty($max)) {
$Test->setFixedScale(0, $max);
}
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, TRUE, 0, 0, FALSE);
//background grid
$Test->drawGrid(4, TRUE, 230, 230, 230, 50);
// Draw the 0 line
//$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",6);
//$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the bar graph
$Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE);
//Set legend properties: width, height and text color and font
$Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 9);
$Test->drawLegend($area_graph_w + 10, 50, $DataSet->GetDataDescription(), 255, 255, 255);
//Set title properties
$Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 10);
$Test->drawTitle(50, 22, strip_tags($header_name[$i - 1]), 50, 50, 80, $chart_size_w - 50);
//------------------
//echo 'not in cache';
$Cache->WriteToCache($graph_id, $DataSet->GetData(), $Test);
//ob_start();
//$Test->Stroke();
//ob_end_clean();
示例3: generate_statistics
//.........这里部分代码省略.........
$DataSet = new pData;
$counter=0;
$maxyvalue=0;
foreach ($grawdata as $datapoint)
{
$DataSet->AddPoint(array($datapoint),"Serie$counter");
$DataSet->AddSerie("Serie$counter");
$counter++;
if ($datapoint>$maxyvalue) $maxyvalue=$datapoint;
}
if ($maxyvalue<10) {++$maxyvalue;}
$counter=0;
foreach ($lbl as $label)
{
$DataSet->SetSerieName($label,"Serie$counter");
$counter++;
}
if ($MyCache->IsInCache("graph".$surveyid,$DataSet->GetData()))
{
$cachefilename=basename($MyCache->GetFileFromCache("graph".$surveyid,$DataSet->GetData()));
}
else
{
$graph = new pChart(1,1);
$graph->setFontProperties($rootdir."/fonts/".$chartfontfile, $chartfontsize);
$legendsize=$graph->getLegendBoxSize($DataSet->GetDataDescription());
if ($legendsize[1]<320) $gheight=420; else $gheight=$legendsize[1]+100;
$graph = new pChart(690+$legendsize[0],$gheight);
$graph->loadColorPalette($homedir.'/styles/'.$admintheme.'/limesurvey.pal');
$graph->setFontProperties($rootdir."/fonts/".$chartfontfile,$chartfontsize);
$graph->setGraphArea(50,30,500,$gheight-60);
$graph->drawFilledRoundedRectangle(7,7,523+$legendsize[0],$gheight-7,5,254,255,254);
$graph->drawRoundedRectangle(5,5,525+$legendsize[0],$gheight-5,5,230,230,230);
$graph->drawGraphArea(255,255,255,TRUE);
$graph->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,90,0,TRUE,5,false);
$graph->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line
$graph->setFontProperties($rootdir."/fonts/".$chartfontfile,$chartfontsize);
$graph->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the bar graph
$graph->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),FALSE);
//$Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie4","1","Important point!");
// Finish the graph
$graph->setFontProperties($rootdir."/fonts/".$chartfontfile, $chartfontsize);
$graph->drawLegend(510,30,$DataSet->GetDataDescription(),255,255,255);
$MyCache->WriteToCache("graph".$surveyid,$DataSet->GetData(),$graph);
$cachefilename=basename($MyCache->GetFileFromCache("graph".$surveyid,$DataSet->GetData()));
unset($graph);
}
} //end if (bar chart)
//Pie Chart
else
{
// this block is to remove the items with value == 0
$i = 0;
while (isset ($gdata[$i]))
{
if ($gdata[$i] == 0)
示例4: createChart
/**
*
* Generate a chart for a question
* @param int $iQuestionID ID of the question
* @param int $iSurveyID ID of the survey
* @param mixed $type Type of the chart to be created - null produces bar chart, any other value produces pie chart
* @param array $lbl An array containing the labels for the chart items
* @param mixed $gdata An array containing the percentages for the chart items
* @param mixed $grawdata An array containing the raw count for the chart items
* @param mixed $cache An object containing [Hashkey] and [CacheFolder]
* @param string $sQuestionType The question type
* @return Name
*/
function createChart($iQuestionID, $iSurveyID, $type = null, $lbl, $gdata, $grawdata, $cache, $oLanguage, $sQuestionType)
{
/* This is a lazy solution to bug #6389. A better solution would be to find out how
the "T" gets passed to this function from the statistics.js file in the first place! */
if (substr($iSurveyID, 0, 1) == "T") {
$iSurveyID = substr($iSurveyID, 1);
}
static $bErrorGenerate = false;
if ($bErrorGenerate) {
return false;
}
$rootdir = Yii::app()->getConfig("rootdir");
$homedir = Yii::app()->getConfig("homedir");
$homeurl = Yii::app()->getConfig("homeurl");
$admintheme = Yii::app()->getConfig("admintheme");
$scriptname = Yii::app()->getConfig("scriptname");
$chartfontfile = Yii::app()->getConfig("chartfontfile");
$chartfontsize = Yii::app()->getConfig("chartfontsize");
$alternatechartfontfile = Yii::app()->getConfig("alternatechartfontfile");
$language = $oLanguage->langcode;
$cachefilename = "";
/* Set the fonts for the chart */
if ($chartfontfile == 'auto') {
// Tested with ar,be,el,fa,hu,he,is,lt,mt,sr, and en (english)
// Not working for hi, si, zh, th, ko, ja : see $config['alternatechartfontfile'] to add some specific language font
$chartfontfile = 'DejaVuSans.ttf';
if (array_key_exists($language, $alternatechartfontfile)) {
$neededfontfile = $alternatechartfontfile[$language];
if (is_file($rootdir . "/fonts/" . $neededfontfile)) {
$chartfontfile = $neededfontfile;
} else {
Yii::app()->setFlashMessage(sprintf(gT('The fonts file %s was not found in <limesurvey root folder>/fonts directory. Please, see the txt file for your language in fonts directory to generate the charts.'), $neededfontfile), 'error');
$bErrorGenerate = true;
// Don't do a graph again.
return false;
}
}
}
if (count($lbl) > 72) {
$DataSet = array(1 => array(1 => 1));
if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet) && Yii::app()->getConfig('debug') < 2) {
$cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
} else {
$graph = new pChart(690, 200);
$graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal');
$graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
$graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
$graph->drawTitle(0, 0, gT('Sorry, but this question has too many answer options to be shown properly in a graph.', 'unescaped'), 30, 30, 30, 690, 200);
$cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet, $graph);
$cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
unset($graph);
}
return $cachefilename;
}
if (array_sum($gdata) == 0) {
$DataSet = array(1 => array(1 => 1));
if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet) && Yii::app()->getConfig('debug') < 2) {
$cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
} else {
$graph = new pChart(690, 200);
$graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal');
$graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
$graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
$graph->drawTitle(0, 0, gT('Sorry, but this question has no responses yet so a graph cannot be shown.', 'unescaped'), 30, 30, 30, 690, 200);
$cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet, $graph);
$cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
unset($graph);
}
return $cachefilename;
}
if (array_sum($gdata) > 0) {
$graph = "";
$p1 = "";
$i = 0;
foreach ($gdata as $data) {
if ($data != 0) {
$i++;
}
}
/* Totatllines is the number of entries to show in the key and we need to reduce the font
and increase the size of the chart if there are lots of them (ie more than 15) */
$totallines = $i;
if ($totallines > 15) {
$gheight = 320 + 6.7 * ($totallines - 15);
$fontsize = 7;
$legendtop = 0.01;
$setcentrey = 0.5 / ($gheight / 320);
//.........这里部分代码省略.........
示例5: pchartAction
public function pchartAction()
{
// $this->_helper->layout->disableLayout();
$this->_helper->layout->setLayout("layout_admin");
include "pData.class";
include "pChart.class";
$this->view->showArray = $this->testdemoAction();
$showdate = array();
$showreport = array();
foreach ($this->view->showArray as $show) {
array_push($showdate, substr($show['date'], strlen($show['date']) - 4, 4));
array_push($showreport, $show['count']);
}
// Dataset definition
$DataSet = new pData();
$DataSet->AddPoint(array_slice($showreport, 0, 26), "Serie1");
$DataSet->AddPoint(array_slice($showdate, 0, 26), "Serie2");
$DataSet->AddSerie("Serie1");
$DataSet->SetAbsciseLabelSerie("Serie2");
$DataSet->SetSerieName("Reports", "Serie1");
$DataSet->SetYAxisName('Report Count');
$DataSet->SetXAxisName('Date');
// Initialise the graph
$Test = new pChart(900, 250);
$Test->setFontProperties("xihei.ttf", 8);
$Test->setGraphArea(50, 30, 780, 200);
$Test->drawFilledRoundedRectangle(7, 7, 793, 248, 5, 255, 255, 255);
$Test->drawRoundedRectangle(5, 5, 795, 249, 5, 230, 230, 230);
$Test->drawGraphArea(255, 255, 255, TRUE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE);
$Test->drawGrid(4, TRUE, 230, 230, 230, 50);
// Draw the 0 line
$Test->setFontProperties("xihei.ttf", 6);
$Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
// Draw the bar graph
$Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE);
// Finish the graph
$Test->setFontProperties("xihei.ttf", 8);
$Test->drawLegend(596, 50, $DataSet->GetDataDescription(), 255, 255, 255);
$Test->setFontProperties("xihei.ttf", 10);
$Test->drawTitle(200, 22, "Reports by Day in Jue.", 50, 50, 50, 585);
$Test->Render("Naked1.png");
//=====================================================================================
// Dataset definition
$DataSet2 = new pData();
$DataSet2->AddPoint(array(38, 22, 606), "Serie1");
$DataSet2->AddPoint(array("Male", "Female", "Unkown"), "Serie2");
$DataSet2->AddAllSeries();
$DataSet2->SetAbsciseLabelSerie("Serie2");
// Initialise the graph
$Test2 = new pChart(300, 200);
$Test2->loadColorPalette("softtones.txt");
$Test2->drawFilledRoundedRectangle(7, 7, 293, 193, 5, 255, 255, 255);
$Test2->drawRoundedRectangle(5, 5, 295, 195, 5, 230, 230, 230);
// This will draw a shadow under the pie chart
$Test2->drawFilledCircle(122, 102, 70, 200, 200, 200);
// Draw the pie chart
$Test2->setFontProperties("tahoma.ttf", 8);
$Test2->drawBasicPieGraph($DataSet2->GetData(), $DataSet2->GetDataDescription(), 120, 100, 70, PIE_PERCENTAGE, 255, 255, 218);
$Test2->drawPieLegend(230, 15, $DataSet2->GetData(), $DataSet2->GetDataDescription(), 250, 250, 250);
$Test2->Render("Naked2.png");
//=====================================================================================
// select province
$db = Zend_Registry::get('db');
$selectprovince = $db->select();
$selectprovince->from('consumer', array("province", "count(*) as count"))->where("pest is null")->group("consumer.province")->order("count desc");
$provinceArray = $db->fetchAll($selectprovince);
$this->view->showprovince = '';
$this->view->showprovincecount = '';
$showprovince = array();
$showprovincecount = array();
foreach ($provinceArray as $province) {
if ($province['province'] == null || $province['province'] == '') {
array_push($showprovince, 'Unkown');
} else {
array_push($showprovince, $province['province']);
}
array_push($showprovincecount, $province['count']);
}
// Dataset definition
$DataSet3 = new pData();
$DataSet3->AddPoint(array_slice($showprovincecount, 0, 20), "Serie1");
$DataSet3->AddPoint(array_slice($showprovince, 0, 20), "Serie2");
$DataSet3->AddSerie("Serie1");
$DataSet3->SetAbsciseLabelSerie("Serie2");
$DataSet3->SetSerieName("Spark Count", "Serie1");
$DataSet3->SetYAxisName('Spark Count');
$DataSet3->SetXAxisName('Province');
Zend_Debug::dump($DataSet3->GetDataDescription());
// Initialise the graph
$Test3 = new pChart(900, 250);
$Test3->setFontProperties("xihei.ttf", 8);
$Test3->setGraphArea(50, 30, 780, 200);
$Test3->drawFilledRoundedRectangle(7, 7, 793, 248, 5, 255, 255, 255);
$Test3->drawRoundedRectangle(5, 5, 795, 249, 5, 230, 230, 230);
$Test3->drawGraphArea(255, 255, 255, TRUE);
$Test3->drawScale($DataSet3->GetData(), $DataSet3->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE);
$Test3->drawGrid(4, TRUE, 230, 230, 230, 50);
// Draw the 0 line
$Test3->setFontProperties("xihei.ttf", 6);
//.........这里部分代码省略.........
示例6: array
require_once "../gd-star-config.php";
$wpconfig = get_wpconfig();
require $wpconfig;
global $gdsr;
$data = GDSRChart::votes_counter();
$values = array();
$titles = array();
foreach ($data as $row) {
$values[] = $row->counter;
$titles[] = $row->vote;
}
include STARRATING_CHART_PATH . "pchart/pData.class";
include STARRATING_CHART_PATH . "pchart/pChart.class";
$data_set = new pData();
$data_set->AddPoint($values, "Serie1");
$data_set->AddPoint($titles, "Serie2");
$data_set->AddAllSeries();
$data_set->SetAbsciseLabelSerie("Serie2");
$chart = new pChart(430, 240);
$chart->loadColorPalette(STARRATING_CHART_PATH . "colors/default.palette");
$chart->drawFilledRoundedRectangle(7, 7, 423, 233, 5, 240, 240, 240);
$chart->drawRoundedRectangle(5, 5, 425, 235, 5, 230, 230, 230);
$chart->setFontProperties(STARRATING_CHART_PATH . "fonts/quicksand.ttf", 8);
$chart->drawPieGraph($data_set->GetData(), $data_set->GetDataDescription(), 180, 130, 130, PIE_PERCENTAGE, TRUE, 50, 20, 5);
$chart->drawPieLegend(370, 15, $data_set->GetData(), $data_set->GetDataDescription(), 250, 250, 250);
$chart->drawFilledRoundedRectangle(16, 16, 301, 34, 5, 220, 220, 220);
$chart->drawFilledRoundedRectangle(15, 15, 300, 33, 5, 250, 250, 250);
$chart->setFontProperties(STARRATING_CHART_PATH . "fonts/quicksand.ttf", 11);
$chart->drawTitle(20, 29, __("Chart with votes distribution", "gd-star-rating"), 250, 50, 50);
$chart->Stroke();
示例7: _createSourcesGraph
protected function _createSourcesGraph()
{
// load pChart graphic library
$this->_loadLibs();
// définition des données à afficher
$dataSet = new pData();
// need config, to know which data user wants to display : visits, unique visitors, pageviews
$sefConfig = Sh404sefFactory::getConfig();
// Google does not allow combining dimension=ga:medium with metric = unique visitors
$dataType = $sefConfig->analyticsDashboardDataType == 'ga:visitors' ? 'ga:visits' : $sefConfig->analyticsDashboardDataType;
$dataTypeString = str_replace('ga:', '', $dataType);
// sort data for proper display
usort($this->_rawData['sources'], array($this, '_sortSourcesDataCompareFunction'));
// we walk the array, pulling out alternatively
// the first and last items
// making the new array having the largest item
// followed by the smallest, then second largest
// then second smallest, ...
// which makes drawing labels much easier
$tmpArray = array();
$even = false;
$max = count($this->_rawData['sources']);
for ($i = 0; $i < $max; $i++) {
if ($even) {
// pull last item in sorted array
$tmpArray[] = array_pop($this->_rawData['sources']);
} else {
// pull array first item
$tmpArray[] = array_shift($this->_rawData['sources']);
}
// flag inversion
$even = !$even;
}
// get data from response
$data = array();
$types = array();
foreach ($tmpArray as $entry) {
$value = $entry->{$dataTypeString};
// do not add empty values, as pChart would choke on that and display a warning
if (!empty($value)) {
$data[] = $value;
$types[] = Sh404sefHelperAnalytics::getReferralLabel($entry->dimension['medium']);
}
}
$dataSet->AddPoint($data, "visits");
$dataSet->AddPoint($types, "types");
$dataSet->addSerie('visits');
$dataSet->SetAbsciseLabelSerie("types");
$label = JText::_('COM_SH404SEF_ANALYTICS_REPORT_SOURCES') . JText::_('COM_SH404SEF_ANALYTICS_REPORT_BY_LABEL') . Sh404sefHelperAnalytics::getDataTypeTitle();
$dataSet->SetSerieName($label, "visits");
// Initialise the graph
$w = intval(0.45 * $this->_options['cpWidth']);
$w = empty($w) ? 160 : $w;
$radius = intval($w * 0.22);
$margin = 5;
$h = intval($w * 0.8);
$centreX = intval(0.5 * $w);
$centreY = intval(0.5 * $h);
$chart = new pChart($w, $h);
$fontSize = 8;
// prepare graph
$chart->setFontProperties($this->_baseChartPath . DS . 'Fonts/arial.ttf', $fontSize);
$chart->loadColorPalette($this->_baseChartPath . DS . 'palettes' . DS . 'tones-2-green-soft.php');
$chart->setGraphArea($margin, $margin, $w - $margin, $h - $margin);
// This will draw a shadow under the pie chart
$chart->drawFilledCircle($centreX + 4, $centreY + 4, $radius, 200, 200, 200);
// Draw the pie chart
$d = $dataSet->GetData();
if (!empty($d)) {
$chart->drawBasicPieGraph($d, $dataSet->GetDataDescription(), $centreX, $centreY, $radius, PIE_PERCENTAGE_LABEL_VALUE, 255, 255, 218);
}
// create a temporary file for
$user =& JFactory::getUser();
// make sure the root tmp dir exists
$rootDir = 'tmp' . DS . 'sh404sef_analytics';
Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $rootDir);
// file name is variable to avoid browser cache
$basePath = $rootDir . DS . md5('useless_' . $user->id . '_hashing') . DS;
// create path and make sure there's an index.html file in it
Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $basePath);
$imageFileName = Sh404sefHelperAnalytics::createTempFile($basePath, $this->_options['report'] . '.' . $this->_options['accountId'] . '.sources.' . $dataTypeString);
$chart->Render(JPATH_ROOT . DS . $imageFileName);
// need cleaning up, so let's remove all report files for that user older than an hour or so
Sh404sefHelperAnalytics::cleanReportsImageFiles(JPATH_ROOT . DS . $basePath, $age = 4000);
return JURI::root() . $imageFileName;
}
示例8: grapher
/**
* This function draw the graphic to be displayed on the user view as an image
*
* @param array $sql_result
* @param string $start_date
* @param string $end_date
* @param string $type
* @author Jorge Frisancho Jibaja
* @version OCT-22- 2010
* @return string
*/
function grapher($sql_result, $start_date, $end_date, $type = "") {
require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
if (empty($start_date)) { $start_date =""; }
if (empty($end_date)) { $end_date =""; }
if ($type == ""){ $type = 'day'; }
$main_year = $main_month_year = $main_day = array();
// get last 8 days/months
$last_days = 5;
$last_months = 3;
for ($i = $last_days; $i >= 0; $i--) {
$main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;
}
for ($i = $last_months; $i >= 0; $i--) {
$main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0;
}
$i = 0;
if (is_array($sql_result) && count($sql_result) > 0) {
foreach ($sql_result as $key => $data) {
//creating the main array
$main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
$main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
if ($i > 500) {
break;
}
$i++;
}
switch ($type) {
case 'day':
$main_date = $main_day;
break;
case 'month':
$main_date = $main_month_year;
break;
case 'year':
$main_date = $main_year;
break;
}
// the nice graphics :D
$labels = array_keys($main_date);
if (count($main_date) == 1) {
$labels = $labels[0];
$main_date = $main_date[$labels];
}
$data_set = new pData();
$data_set->AddPoint($main_date, 'Q');
if (count($main_date)!= 1) {
$data_set->AddPoint($labels, 'Date');
}
$data_set->AddAllSeries();
$data_set->RemoveSerie('Date');
$data_set->SetAbsciseLabelSerie('Date');
$data_set->SetYAxisName(get_lang('Minutes', ''));
$graph_id = api_get_user_id().'AccessDetails'.api_get_course_id().$start_date.$end_date.$type;
$data_set->AddAllSeries();
$cache = new pCache();
// the graph id
$data = $data_set->GetData();
if ($cache->IsInCache($graph_id, $data_set->GetData())) {
//if (0) {
//if we already created the img
// echo 'in cache';
$img_file = $cache->GetHash($graph_id, $data_set->GetData());
} else {
// if the image does not exist in the archive/ folder
// Initialise the graph
$test = new pChart(760, 230);
//which schema of color will be used
$quant_resources = count($data[0]) - 1;
// Adding the color schemma
$test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt');
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
$test->setGraphArea(70, 30, 680, 200);
$test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
$test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
$test->drawGraphArea(255, 255, 255, TRUE);
$test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
$test->drawGrid(4, TRUE, 230, 230, 230, 50);
$test->setLineStyle(2);
//.........这里部分代码省略.........
示例9: createChart
/**
*
* Generate a chart for a question
* @param int $iQuestionID ID of the question
* @param int $iSurveyID ID of the survey
* @param mixed $type Type of the chart to be created - null produces bar chart, any other value produces pie chart
* @param array $lbl An array containing the labels for the chart items
* @param mixed $gdata An array containing the percentages for the chart items
* @param mixed $grawdata An array containing the raw count for the chart items
* @param mixed $cache An object containing [Hashkey] and [CacheFolder]
* @return Name
*/
function createChart($iQuestionID, $iSurveyID, $type = null, $lbl, $gdata, $grawdata, $cache, $oLanguage)
{
/* This is a lazy solution to bug #6389. A better solution would be to find out how
the "T" gets passed to this function from the statistics.js file in the first place! */
if (substr($iSurveyID, 0, 1) == "T") {
$iSurveyID = substr($iSurveyID, 1);
}
$rootdir = Yii::app()->getConfig("rootdir");
$homedir = Yii::app()->getConfig("homedir");
$homeurl = Yii::app()->getConfig("homeurl");
$admintheme = Yii::app()->getConfig("admintheme");
$scriptname = Yii::app()->getConfig("scriptname");
$chartfontfile = Yii::app()->getConfig("chartfontfile");
$chartfontsize = Yii::app()->getConfig("chartfontsize");
$language = Survey::model()->findByPk($iSurveyID)->language;
$statlang = $oLanguage;
$cachefilename = "";
/* Set the fonts for the chart */
if ($chartfontfile == 'auto') {
$chartfontfile = 'vera.ttf';
if ($language == 'ar') {
$chartfontfile = 'KacstOffice.ttf';
} elseif ($language == 'fa') {
$chartfontfile = 'KacstFarsi.ttf';
} elseif ($language == 'el') {
$chartfontfile = 'DejaVuLGCSans.ttf';
} elseif ($language == 'zh-Hant-HK' || $language == 'zh-Hant-TW' || $language == 'zh-Hans') {
$chartfontfile = 'fireflysung.ttf';
}
}
if (array_sum($gdata) > 0) {
$graph = "";
$p1 = "";
$i = 0;
foreach ($gdata as $data) {
if ($data != 0) {
$i++;
}
}
/* Totatllines is the number of entries to show in the key and we need to reduce the font
and increase the size of the chart if there are lots of them (ie more than 15) */
$totallines = $i;
if ($totallines > 15) {
$gheight = 320 + 6.7 * ($totallines - 15);
$fontsize = 7;
$legendtop = 0.01;
$setcentrey = 0.5 / ($gheight / 320);
} else {
$gheight = 320;
$fontsize = 8;
$legendtop = 0.07000000000000001;
$setcentrey = 0.5;
}
if (!$type) {
$DataSet = new pData();
$counter = 0;
$maxyvalue = 0;
foreach ($grawdata as $datapoint) {
$DataSet->AddPoint(array($datapoint), "Serie{$counter}");
$DataSet->AddSerie("Serie{$counter}");
$counter++;
if ($datapoint > $maxyvalue) {
$maxyvalue = $datapoint;
}
}
if ($maxyvalue < 10) {
++$maxyvalue;
}
$counter = 0;
foreach ($lbl as $label) {
$DataSet->SetSerieName($label, "Serie{$counter}");
$counter++;
}
if ($cache->IsInCache("graph" . $language . $iSurveyID, $DataSet->GetData())) {
$cachefilename = basename($cache->GetFileFromCache("graph" . $language . $iSurveyID, $DataSet->GetData()));
} else {
$graph = new pChart(1, 1);
$graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
$legendsize = $graph->getLegendBoxSize($DataSet->GetDataDescription());
if ($legendsize[1] < 320) {
$gheight = 420;
} else {
$gheight = $legendsize[1] + 100;
}
$graph = new pChart(690 + $legendsize[0], $gheight);
$graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal');
$graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
$graph->setGraphArea(50, 30, 500, $gheight - 60);
//.........这里部分代码省略.........
示例10: pData
$dataset = new pData();
//default string value causes problems
$dataset->Data = array();
foreach ($data['series'] as $key => $series) {
$dataset->AddPoint($series, $key);
}
$dataset->AddAllSeries();
foreach ($data['series'] as $key => $series) {
$dataset->SetSerieName($key, $key);
}
//dynamically determine the legend width
$legend_height = get_legend_height($dataset, $CFG->dirroot . "/lib/pChart.1.27d/Fonts/tahoma.ttf", 8);
//create the chart
$chart = new pChart($width, $height);
$chart->Palette = array();
$chart->loadColorPalette($CFG->dirroot . "/lib/pChart.1.27d/Sample/softtones.txt");
//pChart does not correctly wrap colours, so we need to repeat them
$original_count = count($chart->Palette);
for ($i = count($chart->Palette); $i < count($data['series']); $i++) {
$chart->Palette[$i] = $chart->Palette[$i % $original_count];
}
//set up the main chart area
$chart->setFontProperties($CFG->dirroot . "/lib/pChart.1.27d/Fonts/tahoma.ttf", 8);
$chart->setGraphArea(30, 30 + $legend_height, $width - 10, $height - 30);
$chart->drawGraphArea(255, 255, 255, TRUE);
$labelled_data = $dataset->GetData();
//set x-axis labels
$i = 0;
$new_labelled_data = array();
foreach ($labelled_data as $key => $value) {
$new_labelled_data[$key] = $value;
示例11: pChart
array_push($max_rank, $row["max_rank"]);
array_push($time_days, $row["day"]);
}
// Create Data Set
$DataSet->AddPoint($avg_rank, "Average Ranking");
$DataSet->AddPoint($min_rank, "Highest Ranking");
$DataSet->AddPoint($max_rank, "Lowest Ranking");
$DataSet->AddPoint($time_days, "Days");
$DataSet->AddSerie("Average Ranking");
$DataSet->AddSerie("Highest Ranking");
$DataSet->AddSerie("Lowest Ranking");
$DataSet->SetYAxisName("Rank");
$DataSet->SetAbsciseLabelSerie("Days");
// Build Chart
$Test = new pChart(600, 280);
$Test->loadColorPalette("pChart/hardtones.pal");
// Make Evenly Disable Ranks (No Real Numbers) - optimizing by making sure $max is not prime
$max = max($max_rank);
$max = $max + (7 - $max % 7);
for ($divs = 5; ($max - 1) % $divs != 0 && $max % $divs != 0; $divs += 1) {
}
if ($max % $divs == 0) {
$max = $max + 1;
}
if ($divs > 15) {
$divs = 15;
}
// Set Y Scale
$Test->setFixedScale($max, 1, $divs, 0, 0, 1);
// Draw Graph Area
$Test->setFontProperties("Fonts/tahoma.ttf", 10);
示例12: stacked2
function stacked2($data, $title, $filename)
{
// Dataset definition
$DataSet = new pData();
$values = $data['values'];
$keys = $data['keys'];
$bar = new pChart(1040, 230);
for ($i = 0; $i < count($values); $i++) {
$DataSet->AddPoint($values[$i], "Serie" . ($i + 1));
if ($i != 0) {
$DataSet->AddSerie("Serie" . ($i + 1));
$DataSet->SetSerieName($keys[$i - 1], "Serie" . ($i + 1));
}
}
$DataSet->SetAbsciseLabelSerie("Serie1");
$DataSet->SetXAxisFormat("date");
// Initialise the graph
$bar->setDateFormat("M.d");
$bar->setFontProperties("Fonts/consola.ttf", 8);
$bar->setGraphArea(80, 30, 1020, 200);
$bar->drawFilledRoundedRectangle(2, 2, 1037, 227, 5, 240, 240, 240);
$bar->drawRoundedRectangle(0, 0, 1039, 229, 5, 230, 230, 230);
$bar->loadColorPalette('chartcolors.txt', ',');
$bar->drawGraphArea(255, 255, 255, TRUE);
$bar->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, 0, 2, TRUE);
$bar->drawGrid(4, TRUE, 230, 230, 230, 50);
// Draw the 0 line
$bar->setFontProperties("Fonts/consola.ttf", 6);
$bar->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
// Draw the bar graph
$bar->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 100);
$bar->drawLegend(85, 35, $DataSet->GetDataDescription(), 255, 255, 255);
// Finish the graph
$bar->setFontProperties("Fonts/MankSans.ttf", 10);
$bar->drawTitle(10, 20, $title, 100, 100, 100);
$bar->Render($filename);
}
示例13: get_chart
/**
* Displays a chart.
*
* @return void
*/
public function get_chart()
{
$input = JFactory::getApplication()->input;
error_reporting(E_ALL);
include JPATH_COMPONENT . '/helpers/pchart/pData.class.php';
include JPATH_COMPONENT . '/helpers/pchart/pChart.class.php';
JFactory::getDocument()->setMimeEncoding('image/jpg');
$data = $input->getVar('data', '');
$labels = $input->getVar('labels', '');
$colorChart = $input->getInt('color', 8);
$colorPath = JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'pchart' . DS . 'colours' . DS . 'tones-' . $colorChart . '.txt';
$DataSet = new pData();
if ($data) {
$data = explode(',', $data);
$labels = explode(',', $labels);
$DataSet->AddPoint($data, 'Serie1');
$DataSet->AddPoint($labels, 'Serie2');
} else {
$DataSet->AddPoint(array(10, 2, 3, 5, 3), "Serie1");
$DataSet->AddPoint(array("Jan", "Feb", "Mar", "Apr", "May"), "Serie2");
}
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
//-- Initialise the graph
$chart = new pChart(380, 200);
if (JFile::exists($colorPath)) {
$chart->loadColorPalette($colorPath);
}
/*
$chart->drawFilledRoundedRectangle(7, 7, 373, 193, 5, 240, 240, 240);
$chart->drawRoundedRectangle(5, 5, 375, 195, 5, 230, 230, 230);
*/
//-- Draw the pie chart
$chart->setFontProperties(JPATH_COMPONENT . DS . 'helpers' . DS . 'pchart/Fonts/MankSans.ttf', 10);
$chart->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 150, 90, 110, PIE_PERCENTAGE, true, 50, 20, 5);
$chart->drawPieLegend(290, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250);
//-- Spit it out
$chart->Stroke();
return;
}
示例14: drawBarChart
private function drawBarChart($countArray, $nameArray, $title)
{
// Dataset definition
$DataSet = new pData();
$DataSet->AddPoint($countArray, "Serie1");
$DataSet->AddPoint($nameArray, "Serie2");
$DataSet->AddSerie("Serie1");
$DataSet->SetAbsciseLabelSerie("Serie2");
//data legend
$DataSet->SetSerieName("Reports", "Serie1");
$DataSet->SetYAxisName('Report Count');
//$DataSet->SetXAxisName('Score');
// Initialise the graph
$Test = new pChart(700, 250);
$font = "fonts/tahoma.ttf";
$Test->loadColorPalette("fonts/pchart_palette.txt");
//diagram size and style
$Test->setFontProperties($font, 8);
$offset = 25;
$Test->setGraphArea(50 + $offset, 30, 620 + $offset, 200);
$Test->drawFilledRoundedRectangle(7, 7, 693, 233, 5, 240, 240, 240);
$Test->drawRoundedRectangle(5, 5, 695, 235, 5, 230, 230, 230);
$Test->drawGraphArea(255, 255, 255, TRUE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 1);
$Test->drawGrid(4, TRUE, 230, 230, 230, 50);
// // Draw the 0 line
// $Test->setFontProperties($font,6);
// $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the bar graph
$Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE, 80);
// Finish the graph
$Test->setFontProperties($font, 10);
//$Test->drawLegend(610+$offset-5,140,$DataSet->GetDataDescription(),255,255,255);
$Test->drawAxisLegend(10, 208, "Negative", 255, 255, 255, -1, -1, -1, 191, 50, 3);
$Test->drawAxisLegend(610 + $offset - 5, 210, "Positive", 255, 255, 255, -1, -1, -1, 139, 203, 70);
$Test->setFontProperties($font, 10);
$Test->drawTitle(60 + $offset, 20, $title, 50, 50, 50, 585);
$imageFile = "images/drip_bar_chart.png";
$Test->Render($imageFile);
}
示例15: genratePieChartImage
function genratePieChartImage($dataAr)
{
//debug('DATA',$dataAr,2);
$s1 = array();
$s2 = array();
foreach ($dataAr as $key => $val) {
$s1[] = $val;
$s2[] = $key;
}
// Dataset definition
require_once APPPATH . '3rdparty/pchart/pChart/pData.class';
require_once APPPATH . '3rdparty/pchart/pChart/pChart.class';
$path = $this->config->item('csv_upload_path');
$DataSet = new pData();
$DataSet->AddPoint($s1, "Serie1");
$DataSet->AddPoint($s2, "Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
// Initialise the graph
$Test = new pChart(1000, 458);
$Test->drawBackground(232, 234, 234);
$Test->loadColorPalette(APPPATH . '3rdparty/pchart/softtones.txt');
// Draw the pie chart
$Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8);
$Test->drawBasicPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 480, 229, 175);
$Test->drawPieLegend(650, 75, $DataSet->GetData(), $DataSet->GetDataDescription(), 232, 234, 234);
$imgName = uniqid('graph_') . '.png';
$Test->Render($path . $imgName);
return upload_to_amazon_graphImage($imgName, $path);
}