本文整理汇总了PHP中pChart::setColorShades方法的典型用法代码示例。如果您正苦于以下问题:PHP pChart::setColorShades方法的具体用法?PHP pChart::setColorShades怎么用?PHP pChart::setColorShades使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pChart
的用法示例。
在下文中一共展示了pChart::setColorShades方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: barGraph
/**
* Build The Bar Gharph image with given params
* and store in upload/pChart directory.
*
* @param array $params an assoc array of name/value pairs
* @return array $filesPath created image files Path.
*
* @static
*/
static function barGraph($params, $divisionWidth = 44)
{
if (empty($params)) {
return;
}
//get the required directory path.
$config =& CRM_Core_Config::singleton();
//get the default currency.
$currency = $config->defaultCurrency;
$pChartPath = str_replace('templates', 'packages', $config->templateDir);
$pChartPath .= 'pChart/Fonts/';
$uploadDirURL = str_replace('persist/contribute/', 'upload/pChart/', $config->imageUploadURL);
$uploadDirPath = $config->uploadDir . 'pChart/';
//create pchart directory, if exist clean and then create again.
if (is_dir($uploadDirPath)) {
CRM_Utils_File::cleanDir($uploadDirPath);
CRM_Utils_File::createDir($uploadDirPath);
} else {
CRM_Utils_File::createDir($uploadDirPath);
}
require_once 'packages/pChart/pData.class.php';
require_once 'packages/pChart/pChart.class.php';
$chartCount = 0;
$filesValues = array();
foreach ($params as $chartIndex => $chartValues) {
$chartCount++;
$shades = 0;
$names = $values = array();
foreach ($chartValues['values'] as $indexName => $indexValue) {
$names[] = $indexName;
$values[] = $indexValue;
$shades++;
}
$legend = CRM_Utils_Array::value('legend', $chartValues);
$xname = CRM_Utils_Array::value('xname', $chartValues);
$yname = CRM_Utils_Array::value('yname', $chartValues);
//calculate max scale for graph.
$maxScale = ceil(max($values) * 1.1);
$fontSize = 8;
$angleOfIncline = 45;
$monetaryformatting = true;
require_once 'CRM/Utils/Money.php';
$formatedMoney = CRM_Utils_Money::format(max($values));
$positions = imageftbbox($fontSize, 0, $pChartPath . "tahoma.ttf", $formatedMoney);
$scaleTextWidth = $positions[2] - $positions[0];
//need to increase Ysize if we incline money value.
$increaseYBy = 0;
$inclinePositions = imageftbbox($fontSize, $angleOfIncline, $pChartPath . "tahoma.ttf", $formatedMoney);
$inclineTextWidth = $inclinePositions[2] - $inclinePositions[0];
if ($inclineTextWidth > $divisionWidth) {
$increaseYBy = $inclineTextWidth / 2;
}
//Initialise the co-ordinates.
$xComponent = 20;
$yComponent = 35;
$ySize = 300;
//calculate coords.
$x1 = $xComponent + $scaleTextWidth;
$y1 = $yComponent + $increaseYBy;
$ySize += $increaseYBy;
$y2 = $ySize - $yComponent;
//calculate x axis size as per number of months.
$x2 = $xComponent + $divisionWidth + $scaleTextWidth + (count($chartValues['values']) - 1) * $divisionWidth;
$xSize = $x2 + $xComponent;
$dataSet = new pData();
$dataSet->AddPoint($values, "Serie1");
$dataSet->AddPoint($names, "Serie2");
$dataSet->AddSerie("Serie1");
$dataSet->SetAbsciseLabelSerie("Serie2");
//Initialise the graph
$chart = new pChart($xSize, $ySize);
$chart->setFontProperties($pChartPath . "tahoma.ttf", $fontSize);
$chart->setGraphArea($x1, $y1, $x2, $y2);
//set the y axis scale.
$chart->setFixedScale(0, $maxScale, 1);
$chart->drawFilledRoundedRectangle(0, 0, $xSize, $ySize, 5, 240, 240, 240);
$chart->drawRoundedRectangle(0, 0, $xSize, $ySize, 5, 230, 230, 230);
$chart->drawGraphArea(255, 255, 255, TRUE);
$chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 1, FALSE, $divisionWidth, $monetaryformatting);
$chart->drawGrid(4, TRUE, 230, 230, 230, 50);
//set colors.
$chart->setColorShades($shades, self::$_colors);
//Draw the bar chart
$chart->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), TRUE, 80, true);
//get the series values and write at top.
$chart->setColorPalette(0, 0, 0, 255);
$dataDesc = $dataSet->GetDataDescription();
$chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), $dataDesc['Values'], $monetaryformatting, $angleOfIncline);
//Write the title
if ($legend) {
$chart->setFontProperties($pChartPath . "tahoma.ttf", 10);
//.........这里部分代码省略.........