/** * Generates data for OFC2 line chart in json format * * @return void */ public function get_laba_rugi() { $this->load->plugin('ofc2'); $this->load->model('jurnal_model'); $model_data = $this->jurnal_model->get_laba_rugi_data(); $bulan_data = array("Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"); for ($i = date('n') + 1; $i <= 12; $i++) { $pendapatan_kredit = isset($model_data[$i][date('Y') - 1][4][0]) ? $model_data[$i][date('Y') - 1][4][0] : 0; $pendapatan_debit = isset($model_data[$i][date('Y') - 1][4][1]) ? $model_data[$i][date('Y') - 1][4][1] : 0; $beban_kredit = isset($model_data[$i][date('Y') - 1][5][0]) ? $model_data[$i][date('Y') - 1][5][0] : 0; $beban_debit = isset($model_data[$i][date('Y') - 1][5][1]) ? $model_data[$i][date('Y') - 1][5][1] : 0; $data[] = $pendapatan_kredit - $pendapatan_debit - ($beban_debit - $beban_kredit); $thn = date('y') - 1; $thn = strlen($thn) == 1 ? '0' . $thn : $thn; $x_data[] = $bulan_data[$i - 1] . "'" . $thn; } for ($i = 1; $i <= date('n'); $i++) { $pendapatan_kredit = isset($model_data[$i][date('Y')][4][0]) ? $model_data[$i][date('Y')][4][0] : 0; $pendapatan_debit = isset($model_data[$i][date('Y')][4][1]) ? $model_data[$i][date('Y')][4][1] : 0; $beban_kredit = isset($model_data[$i][date('Y')][5][0]) ? $model_data[$i][date('Y')][5][0] : 0; $beban_debit = isset($model_data[$i][date('Y')][5][1]) ? $model_data[$i][date('Y')][5][1] : 0; $data[] = $pendapatan_kredit - $pendapatan_debit - ($beban_debit - $beban_kredit); $x_data[] = $bulan_data[$i - 1] . "'" . date('y'); } $max = (int) max($data); $maxlen = strlen($max); $up = round($max, -($maxlen - 1)); $min = (int) min($data); $minlen = strlen($min); $down = round($min, -($minlen - 1)); $abs_max = (int) max(abs($max), abs($min)); $len = strlen($abs_max); $round = round($abs_max, -($len - 1)); $step = '1' . substr($round, 1); $up = $max > $up ? $up + $step : $up; $down = $min < $down ? $down - $step : $down; $d = new hollow_dot(); $d->size(4)->halo_size(1)->colour('#668053'); $line = new line(); $line->set_values($data); $line->set_default_dot_style($d); $line->set_width(5); $line->set_colour('#7491a0'); $x_labels = new x_axis_labels(); $x_labels->set_labels($x_data); $x = new x_axis(); $x->set_labels($x_labels); $x->set_grid_colour('#bfb8b3'); $y = new y_axis(); $y->set_grid_colour('#bfb8b3'); $y->set_range($down, $up, $step); $chart = new open_flash_chart(); $chart->add_element($line); $chart->set_x_axis($x); $chart->set_y_axis($y); $chart->set_bg_colour('#FFFFFF'); echo $chart->toPrettyString(); }
function get_statistic() { $this->load->library('OpenFlashChartLib', NULL, 'OFCL'); $data_1 = array(); $data_2 = array(); // generate 7 data points for ($i = 0; $i <= 7; $i++) { $x = mktime(0, 0, 0, date("m"), date("d") - $i, date('Y')); $param['sms_date'] = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y"))); $param['user_id'] = $this->session->userdata('id_user'); $y = $this->Kalkun_model->get_sms_used('date', $param); $data_1[] = new scatter_value($x, $y); $data_2[] = $y; } $def = new solid_dot(); $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS'); $line = new scatter_line('#21759B', 3); $line->set_values($data_1); $line->set_default_dot_style($def); $line->set_key("SMS used in last 7 days", 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y'))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:M-d#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(1); $labels->rotate(45); // finally attach the label definition to the x axis $x->set_labels($labels); $y = new y_axis(); if (max($data_2) > 0) { $max = max($data_2); } else { $max = 10; } $y->set_range(0, $max, 10); $chart = new open_flash_chart(); //$chart->set_title( $title ); $chart->add_element($line); $chart->set_x_axis($x); $chart->set_y_axis($y); echo $chart->toPrettyString(); }
/** * Method to render a statistical chart using Open Flash library. * * @return false if someting wrong */ function render() { $values = array(); foreach ($this->values as $number_variable => $variable) { $values[$number_variable] = (int) $variable; } $area = new area(); $area->set_default_dot_style(new hollow_dot()); $area->set_colour('#5B56B6'); $area->set_fill_alpha(0.4); $area->set_values($values); $area->set_key('Values', 12); $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_vertical(); $x_labels->set_colour('#A2ACBA'); $x_labels->set_labels($this->legend); $x = new x_axis(); $x->set_colour('#A2ACBA'); $x->set_grid_colour('#D7E4A3'); $x->set_offset(false); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $y = new y_axis(); $y_max = max($values) > 0 ? max($values) : 4; $y_mod = (int) ($y_max / 4 + 1); $y_max += $y_mod - $y_max % $y_mod; $y->set_range(0, $y_max, $y_mod); $y->labels = null; $y->set_offset(false); $chart = new open_flash_chart(); $chart->set_x_axis($x); $chart->add_y_axis($y); $chart->add_element($area); return $chart; }
function _render_statistic($x = array(), $yout = array(), $yin = array(), $type = 'bar', $points) { $this->load->helper('date'); $this->load->library('OpenFlashChartLib', NULL, 'OFCL'); $data_1 = array(); $data_2 = array(); $data_3 = array(); switch ($type) { case 'bar': for ($i = 0; $i <= $points; $i++) { $data_1[$i] = $x[$i]; $data_2[$i] = (int) $yout[$i]; // force to integer $data_3[$i] = (int) $yin[$i]; // force to integer } $data_1 = array_reverse($data_1); $data_2 = array_reverse($data_2); $data_3 = array_reverse($data_3); $bar_1 = new bar(); $bar_1->set_values($data_3); $bar_1->set_colour('#639F45'); $bar_1->key(lang('kalkun_incoming_sms'), 10); $bar_1->set_tooltip('#x_label#<br>#val# SMS'); //$bar_1->set_key("SMS used in last 7 days", 10); $bar_2 = new bar(); $bar_2->set_values($data_2); $bar_2->set_colour('#21759B'); $bar_2->key(lang('kalkun_outgoing_sms'), 10); $bar_2->set_tooltip('#x_label#<br>#val# SMS'); $x = new x_axis(); $labels = new x_axis_labels(); $labels->set_labels($data_1); $labels->set_steps(1); $x->set_labels($labels); $y = new y_axis(); $max = max(max($data_2), max($data_3)); if ($max < 10) { $max = 10; } $max = ceil($max / 5) * 5; $range = ceil($max / 5); $range = ceil($range / 10) * 10; $y->set_range(0, $max, $range); $element1 = $bar_1; $element2 = $bar_2; break; case 'line': for ($i = 0; $i <= 7; $i++) { $data_1[$i] = new scatter_value($x[$i], $yin[$i]); $data_2[$i] = new scatter_value($x[$i], $yout[$i]); $data_3[$i] = (int) $yin[$i]; $data_4[$i] = (int) $yout[$i]; } $def = new solid_dot(); $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS'); $line_1 = new scatter_line('#639F45', 3); $line_1->set_values($data_1); $line_1->set_default_dot_style($def); $line_1->set_key("Incoming SMS", 10); $line_2 = new scatter_line('#21759B', 3); $line_2->set_values($data_2); $line_2->set_default_dot_style($def); $line_2->set_key("Outgoing SMS", 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y'))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:M-d#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(1); $labels->rotate(45); // finally attach the label definition to the x axis $x->set_labels($labels); $y = new y_axis(); $max = max(max($data_3), max($data_4)); if ($max < 1) { $max = 10; } $y->set_range(0, $max, round($max / 100) * 10); $element1 = $line_1; $element2 = $line_2; break; } $chart = new open_flash_chart(); $chart->add_element($element1); $chart->add_element($element2); $chart->set_x_axis($x); $chart->set_y_axis($y); echo $chart->toPrettyString(); }
'); $deposits = array(); $withdrawals = array(); $weeks = array(); while ($row = mysql_fetch_assoc($result)) { $weeks[] = date('d.m.Y', $row['stamp']); $deposits[] = round($row['deposits'], 2); $withdrawals[] = -round($row['withdrawals'], 2); } //lines $line1 = new line(); $line1->set_values($deposits); $line1->set_colour('#00FF00'); $line2 = new line(); $line2->set_values($withdrawals); $line2->set_colour('#FF0000'); //axises $axis_x = new x_axis(); $axis_x_labels = new x_axis_labels(); $axis_x_labels->set_labels($weeks); $axis_x->set_labels($axis_x_labels); $axis_y = new y_axis(); $axis_y->range(0, max(max($deposits), max($withdrawals)), 1000); //chart $chart = new open_flash_chart(); $chart->set_y_axis($axis_y); $chart->set_x_axis($axis_x); $chart->add_element($line1); $chart->add_element($line2); $chart->set_bg_colour('#FFFFFF'); echo $chart->toPrettyString();
} //Prevent error on no data if (count($datalist < 1)) { $datalist[] = 0; $labellist[] = 0; } $title = new title("Checking account forecast"); $default_dot = new dot(); $default_dot->tooltip('$#val#'); $line = new line(); $line->set_values($datalist); $line->set_default_dot_style($default_dot); $x_labels = new x_axis_labels(); $x_labels->rotate(45); $x_labels->set_labels($labellist); $x_labels->set_steps(3); $x = new x_axis(); $x->set_labels($x_labels); $y = new y_axis(); $y->set_range(min(min($datalist) - 10, 0), round(max($datalist) * 1.1)); $y->set_label_text("\$#val#"); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($line); $chart->set_x_axis($x); $chart->set_y_axis($y); $chart->set_bg_colour('#FFFFFF'); echo $chart->toPrettyString(); ?>
public function GetRenderContent(WebPage $oPage, $aExtraParams = array(), $sId) { $sHtml = ''; // Add the extra params into the filter if they make sense for such a filter $bDoSearch = utils::ReadParam('dosearch', false); if ($this->m_oSet == null) { $aQueryParams = array(); if (isset($aExtraParams['query_params'])) { $aQueryParams = $aExtraParams['query_params']; } if ($this->m_sStyle != 'links') { $oAppContext = new ApplicationContext(); $sClass = $this->m_oFilter->GetClass(); $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($sClass)); $aCallSpec = array($sClass, 'MapContextParam'); if (is_callable($aCallSpec)) { foreach ($oAppContext->GetNames() as $sContextParam) { $sParamCode = call_user_func($aCallSpec, $sContextParam); //Map context parameter to the value/filter code depending on the class if (!is_null($sParamCode)) { $sParamValue = $oAppContext->GetCurrentValue($sContextParam, null); if (!is_null($sParamValue)) { $aExtraParams[$sParamCode] = $sParamValue; } } } } foreach ($aFilterCodes as $sFilterCode) { $externalFilterValue = utils::ReadParam($sFilterCode, '', false, 'raw_data'); $condition = null; if (isset($aExtraParams[$sFilterCode])) { $condition = $aExtraParams[$sFilterCode]; } if ($bDoSearch && $externalFilterValue != "") { // Search takes precedence over context params... unset($aExtraParams[$sFilterCode]); if (!is_array($externalFilterValue)) { $condition = trim($externalFilterValue); } else { if (count($externalFilterValue) == 1) { $condition = trim($externalFilterValue[0]); } else { $condition = $externalFilterValue; } } } if (!is_null($condition)) { $sOpCode = null; // default operator if (is_array($condition)) { // Multiple values, add them as AND X IN (v1, v2, v3...) $sOpCode = 'IN'; } $this->AddCondition($sFilterCode, $condition, $sOpCode); } } if ($bDoSearch) { // Keep the table_id identifying this table if we're performing a search $sTableId = utils::ReadParam('_table_id_', null, false, 'raw_data'); if ($sTableId != null) { $aExtraParams['table_id'] = $sTableId; } } } $aOrderBy = array(); if (isset($aExtraParams['order_by'])) { // Convert the string describing the order_by parameter into an array // The syntax is +attCode1,-attCode2 // attCode1 => ascending, attCode2 => descending $aTemp = explode(',', $aExtraParams['order_by']); foreach ($aTemp as $sTemp) { $aMatches = array(); if (preg_match('/^([+-])?(.+)$/', $sTemp, $aMatches)) { $bAscending = true; if ($aMatches[1] == '-') { $bAscending = false; } $aOrderBy[$aMatches[2]] = $bAscending; } } } $this->m_oSet = new CMDBObjectSet($this->m_oFilter, $aOrderBy, $aQueryParams); } switch ($this->m_sStyle) { case 'count': if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $aValues = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $aValues[$iRow] = $sValue; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = $sHtmlValue; $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); $oAppContext = new ApplicationContext(); $sParams = $oAppContext->GetForLink(); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $this->m_oFilter->DeepClone(); $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow])); $oSubsetSearch->AddConditionExpression($oCondition); $sFilter = urlencode($oSubsetSearch->serialize()); $aData[] = array('group' => $aLabels[$iRow], 'value' => "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search&dosearch=1&{$sParams}&filter={$sFilter}\">{$iCount}</a>"); // TO DO: add the context information } $aAttribs = array('group' => array('label' => $sGroupByLabel, 'description' => ''), 'value' => array('label' => Dict::S('UI:GroupBy:Count'), 'description' => Dict::S('UI:GroupBy:Count+'))); $sFormat = isset($aExtraParams['format']) ? $aExtraParams['format'] : 'UI:Pagination:HeaderNoSelection'; $sHtml .= $oPage->GetP(Dict::Format($sFormat, $iTotalCount)); $sHtml .= $oPage->GetTable($aAttribs, $aData); } else { // Simply count the number of elements in the set $iCount = $this->m_oSet->Count(); $sFormat = 'UI:CountOfObjects'; if (isset($aExtraParams['format'])) { $sFormat = $aExtraParams['format']; } $sHtml .= $oPage->GetP(Dict::Format($sFormat, $iCount)); } break; case 'join': $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array(); if (!isset($aExtraParams['group_by'])) { $sHtml .= $oPage->GetP(Dict::S('UI:Error:MandatoryTemplateParameter_group_by')); } else { $aGroupByFields = array(); $aGroupBy = explode(',', $aExtraParams['group_by']); foreach ($aGroupBy as $sGroupBy) { $aMatches = array(); if (preg_match('/^(.+)\\.(.+)$/', $sGroupBy, $aMatches) > 0) { $aGroupByFields[] = array('alias' => $aMatches[1], 'att_code' => $aMatches[2]); } } if (count($aGroupByFields) == 0) { $sHtml .= $oPage->GetP(Dict::Format('UI:Error:InvalidGroupByFields', $aExtraParams['group_by'])); } else { $aResults = array(); $aCriteria = array(); while ($aObjects = $this->m_oSet->FetchAssoc()) { $aKeys = array(); foreach ($aGroupByFields as $aField) { $sAlias = $aField['alias']; if (is_null($aObjects[$sAlias])) { $aKeys[$sAlias . '.' . $aField['att_code']] = ''; } else { $aKeys[$sAlias . '.' . $aField['att_code']] = $aObjects[$sAlias]->Get($aField['att_code']); } } $sCategory = implode($aKeys, ' '); $aResults[$sCategory][] = $aObjects; $aCriteria[$sCategory] = $aKeys; } $sHtml .= "<table>\n"; // Construct a new (parametric) query that will return the content of this block $oBlockFilter = $this->m_oFilter->DeepClone(); $aExpressions = array(); $index = 0; foreach ($aGroupByFields as $aField) { $aExpressions[] = '`' . $aField['alias'] . '`.`' . $aField['att_code'] . '` = :param' . $index++; } $sExpression = implode(' AND ', $aExpressions); $oExpression = Expression::FromOQL($sExpression); $oBlockFilter->AddConditionExpression($oExpression); $aExtraParams['menu'] = false; foreach ($aResults as $sCategory => $aObjects) { $sHtml .= "<tr><td><h1>{$sCategory}</h1></td></tr>\n"; if (count($aDisplayAliases) == 1) { $aSimpleArray = array(); foreach ($aObjects as $aRow) { $oObj = $aRow[$aDisplayAliases[0]]; if (!is_null($oObj)) { $aSimpleArray[] = $oObj; } } $oSet = CMDBObjectSet::FromArray($this->m_oFilter->GetClass(), $aSimpleArray); $sHtml .= "<tr><td>" . cmdbAbstractObject::GetDisplaySet($oPage, $oSet, $aExtraParams) . "</td></tr>\n"; } else { $index = 0; $aArgs = array(); foreach ($aGroupByFields as $aField) { $aArgs['param' . $index] = $aCriteria[$sCategory][$aField['alias'] . '.' . $aField['att_code']]; $index++; } $oSet = new CMDBObjectSet($oBlockFilter, array(), $aArgs); $sHtml .= "<tr><td>" . cmdbAbstractObject::GetDisplayExtendedSet($oPage, $oSet, $aExtraParams) . "</td></tr>\n"; } } $sHtml .= "</table>\n"; } } break; case 'list': $aClasses = $this->m_oSet->GetSelectedClasses(); $aAuthorizedClasses = array(); if (count($aClasses) > 1) { // Check the classes that can be read (i.e authorized) by this user... foreach ($aClasses as $sAlias => $sClassName) { if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $this->m_oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) { $aAuthorizedClasses[$sAlias] = $sClassName; } } if (count($aAuthorizedClasses) > 0) { if ($this->m_oSet->Count() > 0) { $sHtml .= cmdbAbstractObject::GetDisplayExtendedSet($oPage, $this->m_oSet, $aExtraParams); } else { // Empty set $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay')); } } else { // Not authorized $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay')); } } else { // The list is made of only 1 class of objects, actions on the list are possible if ($this->m_oSet->Count() > 0 && UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) { $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams); } else { $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay')); $sClass = $this->m_oFilter->GetClass(); $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true; if ($bDisplayMenu) { if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) { $sLinkTarget = ''; $oAppContext = new ApplicationContext(); $sParams = $oAppContext->GetForLink(); // 1:n links, populate the target object as a default value when creating a new linked object if (isset($aExtraParams['target_attr'])) { $sLinkTarget = ' target="_blank" '; $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id']; } $sDefault = ''; if (!empty($aExtraParams['default'])) { foreach ($aExtraParams['default'] as $sKey => $sValue) { $sDefault .= "&default[{$sKey}]={$sValue}"; } } $sHtml .= $oPage->GetP("<a{$sLinkTarget} href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=new&class={$sClass}&{$sParams}{$sDefault}\">" . Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass)) . "</a>\n"); } } } } break; case 'links': //$bDashboardMode = isset($aExtraParams['dashboard']) ? ($aExtraParams['dashboard'] == 'true') : false; //$bSelectMode = isset($aExtraParams['select']) ? ($aExtraParams['select'] == 'true') : false; if ($this->m_oSet->Count() > 0 && UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) { //$sLinkage = isset($aExtraParams['linkage']) ? $aExtraParams['linkage'] : ''; $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams); } else { $sClass = $this->m_oFilter->GetClass(); $oAttDef = MetaModel::GetAttributeDef($sClass, $this->m_aParams['target_attr']); $sTargetClass = $oAttDef->GetTargetClass(); $sHtml .= $oPage->GetP(Dict::Format('UI:NoObject_Class_ToDisplay', MetaModel::GetName($sTargetClass))); $bDisplayMenu = isset($this->m_aParams['menu']) ? $this->m_aParams['menu'] == true : true; if ($bDisplayMenu) { if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) { $oAppContext = new ApplicationContext(); $sParams = $oAppContext->GetForLink(); $sDefaults = ''; if (isset($this->m_aParams['default'])) { foreach ($this->m_aParams['default'] as $sName => $sValue) { $sDefaults .= '&' . urlencode($sName) . '=' . urlencode($sValue); } } $sHtml .= $oPage->GetP("<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=modify_links&class={$sClass}&sParams&link_attr=" . $aExtraParams['link_attr'] . "&id=" . $aExtraParams['object_id'] . "&target_class={$sTargetClass}&addObjects=true{$sDefaults}\">" . Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass)) . "</a>\n"); } } } break; case 'details': while ($oObj = $this->m_oSet->Fetch()) { $sHtml .= $oObj->GetDetails($oPage); // Still used ??? } break; case 'actions': $sClass = $this->m_oFilter->GetClass(); $oAppContext = new ApplicationContext(); $bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false; if ($bContextFilter) { $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass())); foreach ($oAppContext->GetNames() as $sFilterCode) { $sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null); if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) { $this->AddCondition($sFilterCode, $sContextParamValue); } } $aQueryParams = array(); if (isset($aExtraParams['query_params'])) { $aQueryParams = $aExtraParams['query_params']; } $this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams); } $iCount = $this->m_oSet->Count(); $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize()); $sHtml .= '<p><a class="actions" href="' . $sHyperlink . '">'; // Note: border set to 0 due to various browser interpretations (IE9 adding a 2px border) $sHtml .= MetaModel::GetClassIcon($sClass, true, 'float;left;margin-right:10px;border:0;'); $sHtml .= MetaModel::GetName($sClass) . ': ' . $iCount . '</a></p>'; $sParams = $oAppContext->GetForLink(); $sHtml .= '<p>'; if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) { $sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=new&class={$sClass}&{$sParams}\">" . Dict::Format('UI:ClickToCreateNew', MetaModel::GetName($sClass)) . "</a><br/>\n"; } $sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search_form&do_search=0&class={$sClass}&{$sParams}\">" . Dict::Format('UI:SearchFor_Class', MetaModel::GetName($sClass)) . "</a>\n"; $sHtml .= '</p>'; break; case 'summary': $sClass = $this->m_oFilter->GetClass(); $oAppContext = new ApplicationContext(); $sTitle = isset($aExtraParams['title[block]']) ? $aExtraParams['title[block]'] : ''; $sLabel = isset($aExtraParams['label[block]']) ? $aExtraParams['label[block]'] : ''; $sStateAttrCode = isset($aExtraParams['status[block]']) ? $aExtraParams['status[block]'] : 'status'; $sStatesList = isset($aExtraParams['status_codes[block]']) ? $aExtraParams['status_codes[block]'] : ''; $bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false; if ($bContextFilter) { $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass())); foreach ($oAppContext->GetNames() as $sFilterCode) { $sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null); if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) { $this->AddCondition($sFilterCode, $sContextParamValue); } } $aQueryParams = array(); if (isset($aExtraParams['query_params'])) { $aQueryParams = $aExtraParams['query_params']; } $this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams); } // Summary details $aCounts = array(); $aStateLabels = array(); if (!empty($sStateAttrCode) && !empty($sStatesList)) { $aStates = explode(',', $sStatesList); $oAttDef = MetaModel::GetAttributeDef($sClass, $sStateAttrCode); foreach ($aStates as $sStateValue) { $oFilter = $this->m_oFilter->DeepClone(); $oFilter->AddCondition($sStateAttrCode, $sStateValue, '='); $oSet = new DBObjectSet($oFilter); $aCounts[$sStateValue] = $oSet->Count(); $aStateLabels[$sStateValue] = htmlentities($oAttDef->GetValueLabel($sStateValue), ENT_QUOTES, 'UTF-8'); if ($aCounts[$sStateValue] == 0) { $aCounts[$sStateValue] = '-'; } else { $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($oFilter->serialize()); $aCounts[$sStateValue] = "<a href=\"{$sHyperlink}\">{$aCounts[$sStateValue]}</a>"; } } } $sHtml .= '<div class="summary-details"><table><tr><th>' . implode('</th><th>', $aStateLabels) . '</th></tr>'; $sHtml .= '<tr><td>' . implode('</td><td>', $aCounts) . '</td></tr></table></div>'; // Title & summary $iCount = $this->m_oSet->Count(); $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize()); $sHtml .= '<h1>' . Dict::S(str_replace('_', ':', $sTitle)) . '</h1>'; $sHtml .= '<a class="summary" href="' . $sHyperlink . '">' . Dict::Format(str_replace('_', ':', $sLabel), $iCount) . '</a>'; $sHtml .= '<div style="clear:both;"></div>'; break; case 'csv': $bAdvancedMode = utils::ReadParam('advanced', false); $sCsvFile = strtolower($this->m_oFilter->GetClass()) . '.csv'; $sDownloadLink = utils::GetAbsoluteUrlAppRoot() . 'webservices/export.php?expression=' . urlencode($this->m_oFilter->ToOQL(true)) . '&format=csv&filename=' . urlencode($sCsvFile); $sLinkToToggle = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize()) . '&format=csv'; if ($bAdvancedMode) { $sDownloadLink .= '&fields_advanced=1'; $sChecked = 'CHECKED'; } else { $sLinkToToggle = $sLinkToToggle . '&advanced=1'; $sChecked = ''; } $sAjaxLink = $sDownloadLink . '&charset=UTF-8'; // Includes &fields_advanced=1 if in advanced mode /* $sCSVData = cmdbAbstractObject::GetSetAsCSV($this->m_oSet, array('fields_advanced' => $bAdvancedMode)); $sCharset = MetaModel::GetConfig()->Get('csv_file_default_charset'); if ($sCharset == 'UTF-8') { $bLostChars = false; } else { $sConverted = @iconv('UTF-8', $sCharset, $sCSVData); $sRestored = @iconv($sCharset, 'UTF-8', $sConverted); $bLostChars = ($sRestored != $sCSVData); } if ($bLostChars) { $sCharsetNotice = " <span id=\"csv_charset_issue\">"; $sCharsetNotice .= '<img src="../images/error.png" style="vertical-align:middle"/>'; $sCharsetNotice .= "</span>"; $sTip = "<p>".htmlentities(Dict::S('UI:CSVExport:LostChars'), ENT_QUOTES, 'UTF-8')."</p>"; $sTip .= "<p>".htmlentities(Dict::Format('UI:CSVExport:LostChars+', $sCharset), ENT_QUOTES, 'UTF-8')."</p>"; $oPage->add_ready_script("$('#csv_charset_issue').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );"); } else { $sCharsetNotice = ''; } */ $sCharsetNotice = false; $sHtml .= "<div>"; $sHtml .= '<table style="width:100%" class="transparent">'; $sHtml .= '<tr>'; $sHtml .= '<td><a href="' . $sDownloadLink . '">' . Dict::Format('UI:Download-CSV', $sCsvFile) . '</a>' . $sCharsetNotice . '</td>'; $sHtml .= '<td style="text-align:right"><input type="checkbox" ' . $sChecked . ' onClick="window.location.href=\'' . $sLinkToToggle . '\'"> ' . Dict::S('UI:CSVExport:AdvancedMode') . '</td>'; $sHtml .= '</tr>'; $sHtml .= '</table>'; if ($bAdvancedMode) { $sHtml .= "<p>"; $sHtml .= htmlentities(Dict::S('UI:CSVExport:AdvancedMode+'), ENT_QUOTES, 'UTF-8'); $sHtml .= "</p>"; } $sHtml .= "</div>"; $sHtml .= "<div id=\"csv_content_loading\"><div style=\"width: 250px; height: 20px; background: url(../setup/orange-progress.gif); border: 1px #999 solid; margin-left:auto; margin-right: auto; text-align: center;\">" . Dict::S('UI:Loading') . "</div></div><textarea id=\"csv_content\" style=\"display:none;\">\n"; //$sHtml .= htmlentities($sCSVData, ENT_QUOTES, 'UTF-8'); $sHtml .= "</textarea>\n"; $oPage->add_ready_script("\$.post('{$sAjaxLink}', {}, function(data) { \$('#csv_content').html(data); \$('#csv_content_loading').hide(); \$('#csv_content').show();} );"); break; case 'modify': if (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_MODIFY, $this->m_oSet) == UR_ALLOWED_YES) { while ($oObj = $this->m_oSet->Fetch()) { $sHtml .= $oObj->GetModifyForm($oPage); } } break; case 'search': $sStyle = isset($aExtraParams['open']) && $aExtraParams['open'] == 'true' ? 'SearchDrawer' : 'SearchDrawer DrawerClosed'; $sHtml .= "<div id=\"ds_{$sId}\" class=\"{$sStyle}\">\n"; $oPage->add_ready_script(<<<EOF \t\$("#dh_{$sId}").click( function() { \t\t\$("#ds_{$sId}").slideToggle('normal', function() { \$("#ds_{$sId}").parent().resize(); FixSearchFormsDisposition(); } ); \t\t\$("#dh_{$sId}").toggleClass('open'); \t}); EOF ); $aExtraParams['currentId'] = $sId; $sHtml .= cmdbAbstractObject::GetSearchForm($oPage, $this->m_oSet, $aExtraParams); $sHtml .= "</div>\n"; $sHtml .= "<div class=\"HRDrawer\"></div>\n"; $sHtml .= "<div id=\"dh_{$sId}\" class=\"DrawerHandle\">" . Dict::S('UI:SearchToggle') . "</div>\n"; break; case 'open_flash_chart': static $iChartCounter = 0; $oAppContext = new ApplicationContext(); $sContext = $oAppContext->GetForLink(); if (!empty($sContext)) { $sContext = '&' . $sContext; } $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie'; $sTitle = isset($aExtraParams['chart_title']) ? $aExtraParams['chart_title'] : ''; $sGroupBy = isset($aExtraParams['group_by']) ? $aExtraParams['group_by'] : ''; $sGroupByExpr = isset($aExtraParams['group_by_expr']) ? '¶ms[group_by_expr]=' . $aExtraParams['group_by_expr'] : ''; $sFilter = $this->m_oFilter->serialize(); $sHtml .= "<div id=\"my_chart_{$sId}{$iChartCounter}\">If the chart does not display, <a href=\"http://get.adobe.com/flash/\" target=\"_blank\">install Flash</a></div>\n"; $oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }"); if (isset($aExtraParams['group_by_label'])) { $sUrl = urlencode(utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=open_flash_chart¶ms[group_by]={$sGroupBy}{$sGroupByExpr}¶ms[group_by_label]={$aExtraParams['group_by_label']}¶ms[chart_type]={$sChartType}¶ms[chart_title]={$sTitle}¶ms[currentId]={$sId}&id={$sId}&filter=" . urlencode($sFilter)); } else { $sUrl = urlencode(utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=open_flash_chart¶ms[group_by]={$sGroupBy}{$sGroupByExpr}¶ms[chart_type]={$sChartType}¶ms[chart_title]={$sTitle}¶ms[currentId]={$sId}&id={$sId}&filter=" . urlencode($sFilter)); } $oPage->add_ready_script("swfobject.embedSWF(\"../images/open-flash-chart.swf\", \"my_chart_{$sId}{$iChartCounter}\", \"100%\", \"300\",\"9.0.0\", \"expressInstall.swf\",\n\t\t\t\t{\"data-file\":\"" . $sUrl . "\"}, {wmode: 'transparent'} );\n"); $iChartCounter++; if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $aValues = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $aValues[$iRow] = $sValue; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = $sHtmlValue; $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); $idx = 0; $aURLs = array(); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $this->m_oFilter->DeepClone(); $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow])); $oSubsetSearch->AddConditionExpression($oCondition); $aURLs[$idx] = $oSubsetSearch->serialize(); $idx++; } $sURLList = ''; foreach ($aURLs as $index => $sURL) { $sURLList .= "\taURLs[{$index}] = '" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search&format=html{$sContext}&filter=" . urlencode($sURL) . "';\n"; } $oPage->add_script(<<<EOF function ofc_drill_down_{$sId}(index) { \tvar aURLs = new Array(); {$sURLList} \twindow.location.href=aURLs[index]; } EOF ); } break; case 'open_flash_chart_ajax': require_once APPROOT . '/pages/php-ofc-library/open-flash-chart.php'; $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie'; $sId = utils::ReadParam('id', ''); $oChart = new open_flash_chart(); switch ($sChartType) { case 'bars': $oChartElement = new bar_glass(); if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = strip_tags($sHtmlValue); $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); $aChartLabels = array(); $maxValue = 0; foreach ($aGroupBy as $iRow => $iCount) { $oBarValue = new bar_value($iCount); $oBarValue->on_click("ofc_drill_down_{$sId}"); $aData[] = $oBarValue; if ($iCount > $maxValue) { $maxValue = $iCount; } $aChartLabels[] = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8'); } $oYAxis = new y_axis(); $aMagicValues = array(1, 2, 5, 10); $iMultiplier = 1; $index = 0; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; while ($maxValue > $iTop) { $index++; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; if ($index % count($aMagicValues) == 0) { $iMultiplier = $iMultiplier * 10; } } //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n"; $oYAxis->set_range(0, $iTop, $iMultiplier); $oChart->set_y_axis($oYAxis); $oChartElement->set_values($aData); $oXAxis = new x_axis(); $oXLabels = new x_axis_labels(); // set them vertical $oXLabels->set_vertical(); // set the label text $oXLabels->set_labels($aChartLabels); // Add the X Axis Labels to the X Axis $oXAxis->set_labels($oXLabels); $oChart->set_x_axis($oXAxis); } break; case 'pie': default: $oChartElement = new pie(); $oChartElement->set_start_angle(35); $oChartElement->set_animate(true); $oChartElement->set_tooltip('#label# - #val# (#percent#)'); $oChartElement->set_colours(array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664')); if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = strip_tags($sHtmlValue); $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); foreach ($aGroupBy as $iRow => $iCount) { $sFlashLabel = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8'); $PieValue = new pie_value($iCount, $sFlashLabel); //@@ BUG: not passed via ajax !!! $PieValue->on_click("ofc_drill_down_{$sId}"); $aData[] = $PieValue; } $oChartElement->set_values($aData); $oChart->x_axis = null; } } if (isset($aExtraParams['chart_title'])) { // The title has been given in an url, and urlencoded... // and urlencode transforms utf-8 into something similar to ISO-8859-1 // Example: é (C3A9 becomes %E9) // As a consequence, json_encode (called within open-flash-chart.php) // was returning 'null' and the graph was not displayed at all // To make sure that the graph is displayed AND to get a correct title // (at least for european characters) let's transform back into utf-8 ! $sTitle = iconv("ISO-8859-1", "UTF-8//IGNORE", $aExtraParams['chart_title']); // If the title is a dictionnary entry, fetch it $sTitle = Dict::S($sTitle); $oTitle = new title($sTitle); $oChart->set_title($oTitle); $oTitle->set_style("{font-size: 16px; font-family: Tahoma; font-weight: bold; text-align: center;}"); } $oChart->set_bg_colour('#FFFFFF'); $oChart->add_element($oChartElement); $sHtml = $oChart->toPrettyString(); break; default: // Unsupported style, do nothing. $sHtml .= Dict::format('UI:Error:UnsupportedStyleOfBlock', $this->m_sStyle); } return $sHtml; }
public function index2Action() { $this->_helper->layout->disableLayout(); include 'open-flash-chart.php'; $db = Zend_Registry::get('db'); $select = $db->select(); $select->from('report', array('left(create_date,10) as date', 'count(*)'))->where('report.campaign_id = 3')->where("report.state = 'APPROVED'")->group('date')->order('date')->limit(0); $results = $db->fetchAll($select); $array_data = array(); $array_create_date = array(); foreach ($results as $result) { array_push($array_data, (int) $result["count(*)"]); array_push($array_create_date, $result["date"]); } $title = new title("BugsLock Reports By Day"); $y = new y_axis(); $y->set_range(0, 100, 10); $x = new x_axis(); $x_labels = new x_axis_labels(); $x_labels->set_labels($array_create_date); $x_labels->set_steps(2); $x_labels->rotate(40); $x->set_labels($x_labels); //There is a bug on the tooltip of bar: can not show #x_label#. So use bar_stack instead of bar here. // $bar = new bar_filled( '#E2D66A', '#577261' ); // $bar->set_values($array_data); // $bar->set_tooltip('#x_label#: #val#'); $bar = new bar_stack(); $bar->set_colours(array('#E2D66A', '#577261')); foreach ($array_data as $date) { $bar->append_stack(array((int) $date)); } $bar->set_tooltip('#x_label#: #val#'); $this->view->chart3 = new open_flash_chart(); $this->view->chart3->set_title($title); $this->view->chart3->add_element($bar); $this->view->chart3->set_bg_colour('#FFFFFF'); $this->view->chart3->set_x_axis($x); $this->view->chart3->set_y_axis($y); // echo $this->view->chart3->toPrettyString(); }
/** * undocumented function * * @param string $options * @return void * @access public */ function yAxis($options) { $y = null; if (isset($options['y_axis'])) { $y = new y_axis(); $yOptions = $options['y_axis']; if (isset($yOptions['peaks'])) { $min = $yOptions['peaks'][0]; $max = $yOptions['peaks'][1]; $y->set_range(0, $max); if (isset($yOptions['num_steps'])) { $step = $this->ySteps($max, $yOptions['num_steps'], true); $y->set_steps($step); } } if (isset($yOptions['colors'])) { $col = $yOptions['colors'][0]; $gridCol = $yOptions['colors'][1]; $y->set_colours($col, $gridCol); } } return $y; }
protected function RenderChart($oPage, $sId, $aValues, $sDrillDown = '', $aRows = array()) { // 1- Compute Open Flash Chart data // $aValueKeys = array(); $index = 0; if (count($aValues) > 0 && $sDrillDown != '') { $oFilter = DBObjectSearch::FromOQL($sDrillDown); $sClass = $oFilter->GetClass(); $sOQLClause = str_replace('SELECT ' . $sClass, '', $sDrillDown); $aSQLColNames = array_keys(current($aRows)); // Read the list of columns from the current (i.e. first) element of the array $oAppContext = new ApplicationContext(); $sURL = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search_oql&search_form=0&oql_class=' . $sClass . '&format=html&' . $oAppContext->GetForLink() . '&oql_clause='; } $aURLs = array(); foreach ($aValues as $key => $value) { // Make sure that values are integers (so that max() will work....) // and build an array of STRING with the keys (numeric keys are transformed into string by PHP :-( $aValues[$key] = (int) $value; $aValueKeys[] = (string) $key; // Build the custom query for the 'drill down' on each element if ($sDrillDown != '') { $sFilter = $sOQLClause; foreach ($aSQLColNames as $sColName) { $sFilter = str_replace(':' . $sColName, "'" . addslashes($aRows[$key][$sColName]) . "'", $sFilter); $aURLs[$index] = $sURL . urlencode($sFilter); } } $index++; } $oChart = new open_flash_chart(); if ($this->m_sType == 'bars') { $oChartElement = new bar_glass(); if (count($aValues) > 0) { $maxValue = max($aValues); } else { $maxValue = 1; } $oYAxis = new y_axis(); $aMagicValues = array(1, 2, 5, 10); $iMultiplier = 1; $index = 0; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; while ($maxValue > $iTop) { $index++; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; if ($index % count($aMagicValues) == 0) { $iMultiplier = $iMultiplier * 10; } } //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n"; $oYAxis->set_range(0, $iTop, $iMultiplier); $oChart->set_y_axis($oYAxis); $aBarValues = array(); foreach ($aValues as $iValue) { $oBarValue = new bar_value($iValue); $oBarValue->on_click("ofc_drilldown_{$sId}"); $aBarValues[] = $oBarValue; } $oChartElement->set_values($aBarValues); //$oChartElement->set_values(array_values($aValues)); $oXAxis = new x_axis(); $oXLabels = new x_axis_labels(); // set them vertical $oXLabels->set_vertical(); // set the label text $oXLabels->set_labels($aValueKeys); // Add the X Axis Labels to the X Axis $oXAxis->set_labels($oXLabels); $oChart->set_x_axis($oXAxis); } else { $oChartElement = new pie(); $oChartElement->set_start_angle(35); $oChartElement->set_animate(true); $oChartElement->set_tooltip('#label# - #val# (#percent#)'); $oChartElement->set_colours(array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664')); $aData = array(); foreach ($aValues as $sValue => $iValue) { $oPieValue = new pie_value($iValue, $sValue); //@@ BUG: not passed via ajax !!! $oPieValue->on_click("ofc_drilldown_{$sId}"); $aData[] = $oPieValue; } $oChartElement->set_values($aData); $oChart->x_axis = null; } // Title given in HTML //$oTitle = new title($this->m_sTitle); //$oChart->set_title($oTitle); $oChart->set_bg_colour('#FFFFFF'); $oChart->add_element($oChartElement); $sData = $oChart->toPrettyString(); $sData = json_encode($sData); // 2- Declare the Javascript function that will render the chart data\ // $oPage->add_script(<<<EOF function ofc_get_data_{$sId}() { \treturn {$sData}; } EOF ); if (count($aURLs) > 0) { $sURLList = ''; foreach ($aURLs as $index => $sURL) { $sURLList .= "\taURLs[{$index}] = '" . addslashes($sURL) . "';\n"; } $oPage->add_script(<<<EOF function ofc_drilldown_{$sId}(index) { \tvar aURLs = new Array(); {$sURLList} \tvar sURL = aURLs[index]; \t \twindow.location.href = sURL; // Navigate ! } EOF ); } // 3- Insert the Open Flash chart // $oPage->add("<div id=\"{$sId}\"><div>\n"); $oPage->add_ready_script(<<<EOF swfobject.embedSWF(\t"../images/open-flash-chart.swf", \t"{$sId}", \t"100%", "300","9.0.0", \t"expressInstall.swf", \t{"get-data":"ofc_get_data_{$sId}", "id":"{$sId}"}, \t{'wmode': 'transparent'} ); EOF ); }
public function get_jx_json_bar($info, $type = '') { $year = array_keys($info); $price = array_values($info); $chart = new open_flash_chart(); $chart->set_bg_colour('#FFFFFF'); //flash背景颜色 $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_size(12); $x_labels->set_colour('#000000'); if (count($year) > 0) { $x_labels->set_vertical(); } $x_labels->set_labels($year); // // 插入数据 $x = new x_axis(); $x->set_colour('#000000'); $x->set_grid_colour('#dadada'); $x->set_offset(true); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $x->set_offset(true); $chart->set_x_axis($x); // $bar = new bar_filled( '#74b1e0', '#9dc7e8' ); // $bar->set_values( $price ); $price_array = array(); foreach ($price as $k => $v) { $price_array[$k] = new bar_value($v); $price_array[$k]->set_colour('#74b1e0'); if ($type == 'percent') { //$y->set_label_text("#val#%"); $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v) . '%'); } else { $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v)); } } $bar = new bar_glass(); $bar->set_values($price_array); $chart->add_element($bar); // // LOOK: // //$x_legend = new x_legend( '1983 to 2008' ); //$x_legend->set_style( '{font-size: 20px; color: #778877}' ); //$chart->set_x_legend( $x_legend ); // // remove this when the Y Axis is smarter // $y = new y_axis(); $max = $this->get_the_right_y(max($price)); $max = $max > 0 ? $max : 1; $y->set_range(0, ($max / 5 + 1) * 5, $max / 5 + 1); // if ($max > 20 && $max <= 100) { // // $y->set_range(0, $max, 10); // }elseif($max >= 10&&$max<=20){ // $y->set_range(0, $max, 5); // } // else { // $y->set_range(0, $max); // } $y->set_colour('#000000'); $y->set_grid_colour('#dadada'); if ($type == 'percent') { $y->set_label_text(" #val#%"); } else { $y->set_label_text(" #val#"); } $chart->add_y_axis($y); $info = $chart->toPrettyString(); return $info; }
foreach ($data as $label => $value) { if ($max_value < $value) { $max_value = $value; } $y_labels[] = (string) $label; $hbar->append_value(new hbar_value(0, (double) $value)); } $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($hbar); $step_count = $max_value > 0 ? $max_value / 10 : 1; $x = new x_axis(); $x->set_offset(false); $x->set_steps($max_value / 10); $chart->set_x_axis($x); $y = new y_axis(); $y->set_offset(true); $y->set_labels(array_reverse($y_labels)); $chart->add_y_axis($y); if (isset($yaxis_label)) { $y_legend = new y_legend($yaxis_label); $y_legend->set_style('{font-size: 20px; color: #000000}'); $chart->set_y_legend($y_legend); } if (isset($xaxis_label)) { $x_legend = new x_legend($xaxis_label); $x_legend->set_style('{font-size: 20px; color: #000000}'); $chart->set_x_legend($x_legend); } $chart->set_bg_colour("#f3f3f3"); $tooltip = new tooltip();
if ($diff > $max) { $max = $diff; } if ($diff < $min) { $min = $diff; } } } $title = new title("How far from the budget I was each month"); sort($labellist); $x_labels = new x_axis_labels(); $x_labels->rotate(45); $x_labels->set_labels($labellist); $x = new x_axis(); $x->set_labels($x_labels); $y = new y_axis(); $y->set_range(round($min) * 1.1, round($max) * 1.1); $y->set_label_text("\$#val#"); $chart = new open_flash_chart(); $chart->set_title($title); $chart->set_x_axis($x); $chart->set_y_axis($y); $chart->set_bg_colour('#FFFFFF'); foreach ($categorylist as $category) { $color = "#" . substr(md5($category), 0, 6); $default_dot = new dot(); $default_dot->size(3)->colour($color)->tooltip('#key#:<br>$#val#'); $l = new line(); $l->set_default_dot_style($default_dot); $l->set_values($datalist[$category]); $l->set_key($category, 12);
function _setChartdata($config) { require_once JLG_PATH_SITE . '/assets/classes/open-flash-chart/open-flash-chart.php'; $data = $this->get('ChartData'); // Calculate Values for Chart Object $forSum = array(); $againstSum = array(); $matchDayGoalsCount = array(); $round_labels = array(); foreach ($data as $rw) { if (!$rw->homegoalspd) { $rw->homegoalspd = 0; } if (!$rw->guestgoalspd) { $rw->guestgoalspd = 0; } $homeSum[] = (int) $rw->homegoalspd; $awaySum[] = (int) $rw->guestgoalspd; // check, if both results are missing and avoid drawing the flatline of "0" goals for not played games yet if (!$rw->homegoalspd && !$rw->guestgoalspd) { $matchDayGoalsCount[] = null; } else { $matchDayGoalsCount[] = (int) $rw->homegoalspd + $rw->guestgoalspd; } $round_labels[] = $rw->roundcode; } $chart = new open_flash_chart(); //$chart->set_title( $title ); $chart->set_bg_colour($config['bg_colour']); if (!empty($homeSum) && !empty($awaySum)) { if ($config['home_away_stats']) { $bar1 = new $config['bartype_1'](); $bar1->set_values($homeSum); $bar1->set_tooltip(JText::_('COM_JOOMLEAGUE_STATS_HOME') . ": #val#"); $bar1->set_colour($config['bar1']); $bar1->set_on_show(new bar_on_show($config['animation_1'], $config['cascade_1'], $config['delay_1'])); $bar1->set_key(JText::_('COM_JOOMLEAGUE_STATS_HOME'), 12); $bar2 = new $config['bartype_2'](); $bar2->set_values($awaySum); $bar2->set_tooltip(JText::_('COM_JOOMLEAGUE_STATS_AWAY') . ": #val#"); $bar2->set_colour($config['bar2']); $bar2->set_on_show(new bar_on_show($config['animation_2'], $config['cascade_2'], $config['delay_2'])); $bar2->set_key(JText::_('COM_JOOMLEAGUE_STATS_AWAY'), 12); $chart->add_element($bar1); $chart->add_element($bar2); } } // total $d = new $config['dotstyle_3'](); $d->size((int) $config['line3_dot_strength']); $d->halo_size(1); $d->colour($config['line3']); $d->tooltip(JText::_('COM_JOOMLEAGUE_STATS_TOTAL2') . ' #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($matchDayGoalsCount); $line->set_width((int) $config['line3_strength']); $line->set_key(JText::_('COM_JOOMLEAGUE_STATS_TOTAL'), 12); $line->set_colour($config['line3']); $line->on_show(new line_on_show($config['l_animation_3'], $config['l_cascade_3'], $config['l_delay_3'])); $chart->add_element($line); $x = new x_axis(); $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']); $x->set_labels_from_array($round_labels); $chart->set_x_axis($x); $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_STATS_ROUNDS')); $x_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_x_legend($x_legend); $y = new y_axis(); $y->set_range(0, @max($matchDayGoalsCount) + 2, 1); $y->set_steps(round(@max($matchDayGoalsCount) / 8)); $y->set_colours($config['y_axis_colour'], $config['y_axis_colour_inner']); $chart->set_y_axis($y); $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_STATS_GOALS')); $y_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_y_legend($y_legend); $this->chartdata = $chart; }
$tdf = 'd.m.y'; $title = new title('Processed MIMS ' . date($tdf, $time_lookback) . ' - ' . date($tdf)); $title->set_style('{color: #567300; font-size: 14px}'); $bar = new bar_filled('#2020AC', '#202073', 10); $bar->set_values(array_values($x_values)); //BAR CHART $xfs = 11; //x fontsize $yfs = 12; //y fontsize $hfs = 16; //header fontsize //create chart $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); //x-label $x = new x_axis(); $x->set_labels_from_array($x_labels); $chart->set_x_axis($x); //y-label $y_points = 5; $y_max = max($x_values); $y_step = ceil($y_max / $y_points); $y_max = $y_step * ($y_points + 1); $y = new y_axis(); $y->set_range(0, $y_max, $y_step); $chart->set_y_axis($y); //draw data for chart echo $chart->toString(); require_once 'confy_close.php';
protected function renderHTML() { global $g_BizSystem; $sql = "SELECT username, cflags, methods, user_agent, contact from location order by username"; $db = $g_BizSystem->GetDBConnection("Serdb"); $resultSet = $db->query($sql); if ($resultSet === false) { $err = $db->ErrorMsg(); echo $err; exit; } $chart_colors = array(); $chart_colors[0] = '#FF0000'; $chart_colors[1] = '#00FF00'; $chart_colors[2] = '#0000FF'; $chart_colors[3] = '#408080'; $chart_colors[4] = '#330000'; $chart_colors[5] = '#FDD017'; $chart_colors[6] = '#52D017'; $chart_colors[7] = '#6698FF'; $chart_colors[8] = '#00FFFF'; $chart_colors[9] = '#FF00FF'; $chart_colors[10] = '#2554C7'; $chart_colors[11] = '#806D7E'; $chart_colors[12] = '#FF8040'; $chart_colors[13] = '#C0C0C0'; $chart_colors[14] = '#808000'; $chart_colors[15] = '#800000'; $chart_colors_size = 16; $ul_contacts = array(); for ($i = 0; $i <= 5; $i++) { $ul_contacts[$i] = 0; } $prevuser = "******"; $prevcnt = 1; $ul_uas = array(); $ul_uas['asterisk'] = 0; $ul_uas['freeswitch'] = 0; $ul_uas['x-lite'] = 0; $ul_uas['eyebeam'] = 0; $ul_uas['bria'] = 0; $ul_uas['ekiga'] = 0; $ul_uas['twinkle'] = 0; $ul_uas['snom'] = 0; $ul_uas['cisco'] = 0; $ul_uas['linksys'] = 0; $ul_uas['nokia'] = 0; $ul_uas['grandstream'] = 0; $ul_uas['polycom'] = 0; $ul_uas['draytek'] = 0; $ul_uas['avm'] = 0; $ul_uas['sipura'] = 0; $ul_uas['mitel'] = 0; $ul_uas['others'] = 0; $ul_methods = array(); $ul_methods['INVITE'] = 0; $ul_methods['CANCEL'] = 0; $ul_methods['ACK'] = 0; $ul_methods['BYE'] = 0; $ul_methods['REGISTER'] = 0; $ul_methods['OPTIONS'] = 0; $ul_methods['UPDATE'] = 0; $ul_methods['PRACK'] = 0; $ul_methods['SUBSCRIBE'] = 0; $ul_methods['NOTIFY'] = 0; $ul_methods['PUBLISH'] = 0; $ul_methods['MESSAGE'] = 0; $ul_methods['INFO'] = 0; $ul_methods['REFER'] = 0; $ul_methods['OTHERS'] = 0; $ul_methods['NONE'] = 0; $ul_nat = array(); $ul_nat['NATTED'] = 0; $ul_nat['SIPPING'] = 0; $ul_proto = array(); $ul_proto['UDP'] = 0; $ul_proto['TCP'] = 0; $ul_proto['TLS'] = 0; $ul_proto['SCTP'] = 0; $yidx = 0; $ousr = 0; while ($row = $resultSet->fetch()) { $r_username = $row[0]; $r_cflags = $row[1]; $r_methods = $row[2]; $r_user_agent = $row[3]; $r_contact = $row[4]; /* statistics for contacts per user */ if ($yidx == 0) { $prevuser = $r_username; $prevcnt = 1; } else { if ($r_username == $prevuser) { $prevcnt = $prevcnt + 1; } else { $ousr++; if ($prevcnt < 5) { $ul_contacts[$prevcnt] = $ul_contacts[$prevcnt] + 1; } else { $ul_contacts[5] = $ul_contacts[5] + 1; } $prevuser = $r_username; $prevcnt = 1; } } /* known UA stats */ if (isset($r_user_agent)) { if (preg_match('/asterisk/i', $r_user_agent)) { $ul_uas['asterisk'] = $ul_uas['asterisk'] + 1; } else { if (preg_match("/freeswitch/i", $r_user_agent)) { $ul_uas['freeswitch'] = $ul_uas['freeswitch'] + 1; } else { if (preg_match("/x-lite/i", $r_user_agent)) { $ul_uas['x-lite'] = $ul_uas['x-lite'] + 1; } else { if (preg_match("/bria/i", $r_user_agent)) { $ul_uas['bria'] = $ul_uas['bria'] + 1; } else { if (preg_match("/ekiga/i", $r_user_agent)) { $ul_uas['ekiga'] = $ul_uas['ekiga'] + 1; } else { if (preg_match("/twinkle/i", $r_user_agent)) { $ul_uas['twinkle'] = $ul_uas['twinkle'] + 1; } else { if (preg_match("/snom/i", $r_user_agent)) { $ul_uas['snom'] = $ul_uas['snom'] + 1; } else { if (preg_match("/cisco/i", $r_user_agent)) { $ul_uas['cisco'] = $ul_uas['cisco'] + 1; } else { if (preg_match("/linksys/i", $r_user_agent)) { $ul_uas['linksys'] = $ul_uas['linksys'] + 1; } else { if (preg_match("/nokia/i", $r_user_agent)) { $ul_uas['nokia'] = $ul_uas['nokia'] + 1; } else { if (preg_match("/grandstream/i", $r_user_agent)) { $ul_uas['grandstream'] = $ul_uas['grandstream'] + 1; } else { if (preg_match("/polycom/i", $r_user_agent)) { $ul_uas['polycom'] = $ul_uas['polycom'] + 1; } else { if (preg_match("/draytek/i", $r_user_agent)) { $ul_uas['draytek'] = $ul_uas['draytek'] + 1; } else { if (preg_match("/avm/i", $r_user_agent)) { $ul_uas['avm'] = $ul_uas['avm'] + 1; } else { if (preg_match("/sipura/i", $r_user_agent)) { $ul_uas['sipura'] = $ul_uas['sipura'] + 1; } else { if (preg_match("/mitel/i", $r_user_agent)) { $ul_uas['mitel'] = $ul_uas['mitel'] + 1; } else { $ul_uas['others'] = $ul_uas['others'] + 1; } } } } } } } } } } } } } } } } } /* transports */ if (isset($r_contact)) { if (preg_match('/;transport=tcp/i', $r_contact)) { $ul_proto['TCP'] = $ul_proto['TCP'] + 1; } else { if (preg_match("/;transport=tls/i", $r_contact)) { $ul_proto['TLS'] = $ul_proto['TLS'] + 1; } else { if (preg_match("/;transport=sctp/i", $r_contact)) { $ul_proto['SCTP'] = $ul_proto['SCTP'] + 1; } else { $ul_proto['UDP'] = $ul_proto['UDP'] + 1; } } } } /* supported SIP methods stats */ if (isset($r_methods) && $r_methods != 0) { /* 1 - 2^0 INVITE */ if ($r_methods & 1) { $ul_methods['INVITE'] = $ul_methods['INVITE'] + 1; } /* 2 - 2^1 CANCEL */ if ($r_methods & 2) { $ul_methods['CANCEL'] = $ul_methods['CANCEL'] + 1; } /* 3 - 2^2 ACK */ if ($r_methods & 4) { $ul_methods['ACK'] = $ul_methods['ACK'] + 1; } /* 4 - 2^3 BYE */ if ($r_methods & 8) { $ul_methods['BYE'] = $ul_methods['BYE'] + 1; } /* 5 - 2^4 INFO */ if ($r_methods & 16) { $ul_methods['INFO'] = $ul_methods['INFO'] + 1; } /* 6 - 2^5 REGISTER */ if ($r_methods & 32) { $ul_methods['REGISTER'] = $ul_methods['REGISTER'] + 1; } /* 7 - 2^6 SUBSCRIBE */ if ($r_methods & 64) { $ul_methods['SUBSCRIBE'] = $ul_methods['SUBSCRIBE'] + 1; } /* 8 - 2^7 NOTIFY */ if ($r_methods & 128) { $ul_methods['NOTIFY'] = $ul_methods['NOTIFY'] + 1; } /* 9 - 2^8 MESSAGE */ if ($r_methods & 256) { $ul_methods['MESSAGE'] = $ul_methods['MESSAGE'] + 1; } /* 10 - 2^9 OPTIONS */ if ($r_methods & 512) { $ul_methods['OPTIONS'] = $ul_methods['OPTIONS'] + 1; } /* 11 - 2^10 PRACK */ if ($r_methods & 1024) { $ul_methods['PRACK'] = $ul_methods['PRACK'] + 1; } /* 12 - 2^11 UPDATE */ if ($r_methods & 2048) { $ul_methods['UPDATE'] = $ul_methods['UPDATE'] + 1; } /* 13 - 2^12 REFER */ if ($r_methods & 4096) { $ul_methods['REFER'] = $ul_methods['REFER'] + 1; } /* 14 - 2^13 PUBLISH */ if ($r_methods & 8192) { $ul_methods['PUBLISH'] = $ul_methods['PUBLISH'] + 1; } /* 15 - 2^14 OTHER */ if ($r_methods & 16384) { $ul_methods['OTHERS'] = $ul_methods['OTHERS'] + 1; } } else { $ul_methods['NONE'] = $ul_methods['NONE'] + 1; } /* supported NAT stats */ if (isset($r_cflags) && $r_cflags != 0) { if ($r_cflags & 1 << 6) { $ul_nat['NATTED'] = $ul_nat['NATTED'] + 1; } if ($r_cflags & 1 << 7) { $ul_nat['SIPPING'] = $ul_nat['SIPPING'] + 1; } } $yidx = $yidx + 1; } if ($yidx > 0) { $ousr++; if ($prevcnt < 5) { $ul_contacts[$prevcnt] = $ul_contacts[$prevcnt] + 1; } else { $ul_contacts[5] = $ul_contacts[5] + 1; } } /* user agents chart */ $ua_title = new title('User Agents'); $ua_x_labels = new x_axis_labels(); $ua_x_labels->rotate(20); $ua_bar = new bar_glass(); $chart_vals = array(); $chart_lbls = array(); $i = 0; $ymax = 10; foreach ($ul_uas as $key => $val) { if ($val > 0) { $chart_vals[$i] = new bar_value($val); $chart_vals[$i]->set_colour($chart_colors[$i % $chart_colors_size]); $chart_vals[$i]->set_tooltip($key . '<br>#val#'); $chart_lbls[$i] = $key; if ($ymax < $val) { $ymax = $val; } $i = $i + 1; } } $ua_bar->set_values($chart_vals); $ua_x_labels->set_labels($chart_lbls); $x = new x_axis(); $x->set_labels($ua_x_labels); $y = new y_axis(); $y->set_range(0, $ymax, $ymax / 10); $ul_uas_chart = new open_flash_chart(); $ul_uas_chart->set_title($ua_title); $ul_uas_chart->add_element($ua_bar); $ul_uas_chart->set_x_axis($x); $ul_uas_chart->add_y_axis($y); /* supported SIP Methods chart */ $mt_title = new title('Supported SIP Methods'); $mt_x_labels = new x_axis_labels(); $mt_x_labels->rotate(20); $mt_bar = new bar_glass(); $chart_vals = array(); $chart_lbls = array(); $i = 0; $ymax = 10; foreach ($ul_methods as $key => $val) { if ($val > 0) { $chart_vals[$i] = new bar_value($val); $chart_vals[$i]->set_colour($chart_colors[$i % $chart_colors_size]); $chart_vals[$i]->set_tooltip($key . '<br>#val#'); $chart_lbls[$i] = $key; if ($ymax < $val) { $ymax = $val; } $i = $i + 1; } } $mt_bar->set_values($chart_vals); $mt_x_labels->set_labels($chart_lbls); $x = new x_axis(); $x->set_labels($mt_x_labels); $y = new y_axis(); $y->set_range(0, $ymax, $ymax / 10); $mt_chart = new open_flash_chart(); $mt_chart->set_title($mt_title); $mt_chart->add_element($mt_bar); $mt_chart->set_x_axis($x); $mt_chart->add_y_axis($y); /* bar stacks - contacts/user, nat stats, ... */ $cn_title = new title('Contacts and NAT Stats'); $cn_x_labels = new x_axis_labels(); $cn_x_labels->rotate(20); $bar_stack = new bar_stack(); $bar_stack->set_colours($chart_colors); $chart_lbls = array(); $c = 0; $lidx = 0; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($yidx, $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Records<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'All Records'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ousr, $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Online<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Online Users'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_contacts[1], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('1 contact<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[2], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('2 contacts<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[3], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('3 contacts<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[4], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('4 contacts<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[5], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('>=5 contacts <br>#val#'); $i = $i + 1; $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Contacts per AoR'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_nat['NATTED'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Natted<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($yidx - $ul_nat['NATTED'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Not-Natted<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Natted'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_nat['SIPPING'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('SIP Ping<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($yidx - $ul_nat['SIPPING'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('No SIP Ping<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'SIP Ping'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_proto['UDP'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('UDP<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_proto['TCP'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('TCP<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_proto['TLS'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('TLS<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_proto['SCTP'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('SCTP<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Transports'; $cn_x_labels->set_labels($chart_lbls); $x = new x_axis(); $x->set_labels($cn_x_labels); $y = new y_axis(); $y->set_range(0, $yidx, $yidx / 10); $cn_chart = new open_flash_chart(); $cn_chart->set_title($cn_title); $cn_chart->add_element($bar_stack); $cn_chart->set_x_axis($x); $cn_chart->add_y_axis($y); $sHTML = ''; $sHTML .= ' <div align="center"> <p><b>Processed ' . $yidx . ' records.</b></p> </div> '; if ($yidx > 0) { $sHTML .= ' <script type="text/javascript" src="' . APP_URL . '/js/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_ul_uas", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_ul_uas"} ); swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_ul_met", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_ul_met"} ); swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_ul_cns", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_ul_cns"} ); </script> '; $sHTML .= ' <br /> <div align="center"> <div id="div_chart_ul_uas"> </div> <br /> <br /> <div id="div_chart_ul_met"> </div> <br /> <br /> <div id="div_chart_ul_cns"> </div> <br /> <br /> </div> '; $sHTML .= ' <script type="text/javascript"> function get_data_ul_uas() { data = \'' . $ul_uas_chart->toString() . '\'; return data; } function get_data_ul_met() { data = \'' . $mt_chart->toString() . '\'; return data; } function get_data_ul_cns() { data = \'' . $cn_chart->toString() . '\'; return data; } </script> '; } /* if $yidx */ return $sHTML; }
//-----/end get ranges ----------------- // Prepare the x-axis $x = new x_axis(); $x->set_range($lowest, $highest); // Calculate the steps and visible steps $step = ($highest - $lowest) / 60; $step_vis = 2; // do not allow steps to be less than 30 minutes if ($step < 26400) { # 86400 $step = 26400; $step_vis = 1; } $x->set_steps($step); $labels = new x_axis_labels(); $labels->text('#date:Y-m-d#'); $labels->set_steps($step); $labels->visible_steps($step_vis); $labels->rotate(90); $x->set_labels($labels); // Prepare the y-axis $y = new y_axis(); // $maximum is already set above // set the range and y-step $y->set_range(0, $maximum + getIdealYSteps($maximum)); $y->set_steps(getIdealYSteps($maximum)); # $chart->add_element( $s ); $chart->set_x_axis($x); $chart->add_y_axis($y); // echo a pretty ofc-string anyway echo $chart->toPrettyString();
} $max = 0; $title = new title('Jumlah Data Peserta KB Per RT, RW ' . $aRw[$_REQUEST['rwId']]['nama'] . ' Total : ' . $total . ' ( ' . date("D M d Y") . ' ) '); $title->set_style('{font-size:15px; color: #bcd6ff; margin:0px; background-color: #5E83BF;}'); $bar = new bar_3d(); $bar->set_values($jumlah); $bar->colour = '#9999FF'; $bar->set_on_show(new bar_on_show('grow-up', 1, 0)); $labels = new x_axis_labels(); $labels->set_labels($rt); $y_base = new y_axis_base(); $y_base->set_range(0, $maxJumlah + round($maxJumlah / 2), round($maxJumlah / 10)); $x = new x_axis(); $x->set_labels($labels); $x->set_3d(5); $y = new y_axis(); $y->set_labels($y_labels); $tags = new ofc_tags(); $tags->font('Verdana', 10)->colour('#000000')->align_x_center()->text('#y#'); $i = 0; foreach ($jumlah as $j) { $tags->append_tag(new ofc_tag($i, $j)); $i++; } $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); $chart->add_element($tags); $chart->set_x_axis($x); $chart->set_y_axis($y_base); echo $chart->toString();
function getNewUsersByTime($timePhase, $fromDate = '', $toDate = '') { $this->load->library('ofc'); $userId = $this->common->getUserId(); $this->ofc->open_flash_chart(); $this->ofc->set_bg_colour(CHART_BG_COLOR); $toTime = date("Y-m-d", strtotime("-1 day")); if ($timePhase == "7day") { $fromTime = date("Y-m-d", strtotime("-8 day")); $color = CHART_LINE_1; $key = "近7日新增用户"; $title = new title("近7日新增用户统计"); } if ($timePhase == "1month") { $title = new title("近30天新增用户统计"); $fromTime = date("Y-m-d", strtotime("-31 day")); $color = CHART_LINE_2; $key = "近30天新增用户统计"; } if ($timePhase == "3month") { $title = new title("近三个月新增用户统计"); $fromTime = date("Y-m-d", strtotime("-92 day")); $color = CHART_LINE_3; $key = "近三个月新增用户统计"; } if ($timePhase == "all") { $title = new title("所有新增用户统计"); $fromTime = '1970-01-01'; $color = CHART_LINE_4; $key = "所有新增用户统计"; } if ($timePhase == "any") { $title = new title("所有新增用户统计"); $fromTime = $fromDate; $toTime = $toDate; $color = CHART_LINE_4; $key = "所有新增用户统计"; } $fromTime = $this->product->getUserStartDate($userId, $fromTime); $query = $this->newusermodel->getNewUsersByUserId($fromTime, $toTime, $userId); $data = array(); $maxY = 0; $recordCount = $query->num_rows(); $steps = $recordCount - 1 <= 10 ? 2 : (int) (((int) $recordCount - 1) / 10); $xlabelArray = array(); if ($query != null && $query->num_rows() > 0) { foreach ($query->result() as $row) { $dot = new dot(); $dot->size(3)->halo_size(1)->colour($color); $dot->tooltip($row->startdate . " 新增" . $row->totalusers . "用户"); $dot->value((int) $row->totalusers); if ((int) $row->totalusers > $maxY) { $maxY = (int) $row->totalusers; } array_push($xlabelArray, date('y-m-d', strtotime($row->startdate))); array_push($data, $dot); } } $y = new y_axis(); $y->set_range(0, $this->common->getMaxY($maxY), $this->common->getStepY($maxY)); $x = new x_axis(); $x->set_range(0, $recordCount > 1 ? $recordCount - 1 : 1); $x_labels = new x_axis_labels(); $x_labels->set_steps($steps); $x_labels->set_vertical(); $x_labels->set_colour(CHART_LABEL_COLOR); $x_labels->set_size(13); $x_labels->set_labels($xlabelArray); $x_labels->rotate(-25); $x->set_labels($x_labels); $x->set_steps(1); $this->ofc->set_y_axis($y); $this->ofc->set_x_axis($x); $dot = new dot(); $dot->size(3)->halo_size(1)->colour($color); $line = new line(); $line->set_default_dot_style($dot); $line->set_values($data); $line->set_width(2); $line->set_colour($color); $line->colour($color); $line->set_key($key, 12); $this->ofc->add_element($line); $title->set_style("{font-size: 14px; color:#000000; font-family: Verdana; text-align: center;}"); // $x_legend = new x_legend("<a href=\"javascript:changeChartName('chartNewUser')\">新增用户</a> <a href=\"javascript:changeChartName('chartActiveUser')\">活跃用户</a> <a href=\"javascript:changeChartName('chartStartUser')\">启动用户</a>"); // $this->ofc->set_x_legend( $x_legend ); // $x_legend->set_style( '{font-size: 14px; color: #778877}' ); $this->ofc->set_title($title); echo $this->ofc->toPrettyString(); }
} else { $data_step = $data_step_multiplier / 10; } } $data_max = ceil($data_max / $data_step) * $data_step; //DRAW X AXIS $x = new x_axis(); $x->set_offset(false); $xl_tmp = array(); foreach ($dates as $date) { $xl_tmp[] = date('d.m', strtotime($date)); } $x->steps(10); $x->set_labels_from_array($xl_tmp); //DRAW Y AXIS $y = new y_axis(); $y->set_offset(false); $y->set_range(0, $data_max, $data_step); //SET TOOLTIP FORMAT $t = new tooltip(); $t->set_shadow(false); $t->set_stroke(5); $t->set_colour("#cccccc"); $t->set_background_colour("#efefef"); $t->set_body_style("{font-size:10px; font-weight:bold; color:#000000;}"); //PREPARE FINAL CHART AND RETURN IT $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($line_1); $chart->add_element($line_5); //moved above to make sure line 2 is above line 5
foreach ($data as $label => $value) { if ($max_value < $value) { $max_value = $value; } $y_labels[] = (string) $label; $hbar->append_value(new hbar_value(0, (double) $value)); } $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($hbar); $step_count = $max_value > 0 ? $max_value / 10 : 1; $x = new x_axis(); $x->set_offset(false); $x->set_steps($max_value / 10); $chart->set_x_axis($x); $y = new y_axis(); $y->set_offset(true); $y->set_labels($y_labels); $chart->add_y_axis($y); if (isset($yaxis_label)) { $y_legend = new y_legend($yaxis_label); $y_legend->set_style('{font-size: 20px; color: #000000}'); $chart->set_y_legend($y_legend); } if (isset($xaxis_label)) { $x_legend = new x_legend($xaxis_label); $x_legend->set_style('{font-size: 20px; color: #000000}'); $chart->set_x_legend($x_legend); } $chart->set_bg_colour("#f3f3f3"); $tooltip = new tooltip();
$area->set_colour('#8f8fbd'); $area->set_values($price); $area->set_key('Price', 12); $chart->add_element($area); $x_labels = new x_axis_labels(); $x_labels->set_steps(2); $x_labels->set_vertical(); $x_labels->set_colour('#A2ACBA'); $x_labels->set_labels($year); // ²åÈëÊý¾Ý $x = new x_axis(); $x->set_colour('#dadada'); $x->set_grid_colour('#D7E4A3'); $x->set_offset(false); $x->set_steps(4); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); // // LOOK: // $x_legend = new x_legend('1983 to 2008'); $x_legend->set_style('{font-size: 20px; color: #778877}'); $chart->set_x_legend($x_legend); // // remove this when the Y Axis is smarter // $y = new y_axis(); $y->set_range(0, 150, 30); $chart->add_y_axis($y); echo $chart->toPrettyString();
$line_watt->set_fill_colour('#EFC01D'); $line_watt->set_fill_alpha(0.75); $line_watt->set_width(2); $line_watt->set_key('Leistung (W)', 10); $line_watt->set_tooltip("#val# W"); $line_tot_default_dot = new dot(); $line_tot_default_dot->size(4)->halo_size(2); $line_tot = new line(); $line_tot->set_default_dot_style($line_tot_default_dot); $line_tot->set_values($data_tot); $line_tot->set_colour('#A0A000'); $line_tot->set_width(2); $line_tot->set_key('Gesamt (kWh)', 10); $line_tot->set_tooltip("#val# kWh"); $max = max(max($data_watt), $max_val) * 1.15; $y = new y_axis(); $y->set_range(0, $max, round($max * 0.1, -1)); $x_labels = new x_axis_labels(); $x_labels->set_vertical(); $x_labels->set_steps(6); $x_labels->set_colour('#333333'); $x_labels->set_labels($time_axis); $x = new x_axis(); $x->set_colour('#333333'); $x->set_grid_colour('#ffffff'); $x->set_offset(false); $x->set_steps(3); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart = new open_flash_chart(); $chart->set_tooltip($tooltip);
/** flowview_viewchart() * * This function is taken from Slowlog. Given * a title, chart type and chart data, it will * echo the required syntax for the Callback * from the chart page to operate corectly. */ function flowview_viewchart() { global $colors, $config; include $config['base_path'] . "/plugins/flowview/lib/open-flash-chart-object.php"; include $config['base_path'] . "/plugins/flowview/lib/open-flash-chart.php"; $title = $_REQUEST["title"]; $chart_type = "bar"; $column = $_REQUEST["type"]; $sessionid = $_REQUEST["session"]; /* get the chart data from the session */ if (isset($_SESSION['flowview_flows'][$sessionid]['data'])) { $data = $_SESSION['flowview_flows'][$sessionid]['data']; } else { $filter = createfilter($sessionid); $data = $_SESSION['flowview_flows'][$sessionid]['data']; } switch ($column) { case 'flows': $unit = ucfirst($column); $suffix = "Total Flows"; $_SESSION['sess_flows_flows'] = 'on'; break; case 'bytes': $unit = ucfirst($column); $suffix = "Bytes Exchanged"; $_SESSION['sess_flows_bytes'] = 'on'; break; case 'packets': $unit = ucfirst($column); $suffix = "Packets Examined"; $_SESSION['sess_flows_packets'] = 'on'; break; } $columns = $_SESSION['flowview_flows'][$sessionid]['columns']; foreach ($columns as $key => $cdata) { if (strtolower($cdata) == $column) { $column = $key; } } if (sizeof($data)) { $elements = array(); $legend = array(); $maxvalue = 0; if (isset($_REQUEST['exclude']) && $_REQUEST['exclude'] > 0) { for ($i = 0; $i < $_REQUEST['exclude']; $i++) { array_shift($data); } } foreach ($data as $row) { if ($maxvalue < $row[$column]) { $maxvalue = $row[$column]; $scaling = flowview_autoscale($row[$column]); } } $maxvalue = flowview_getmax($maxvalue); $autorange = flowview_autoscale($maxvalue); $maxvalue = $maxvalue / $autorange[0]; $i = 0; foreach ($data as $row) { $elements[$i] = new bar_value(round($row[$column] / $autorange[0], 3)); $elements[$i]->set_colour(flowview_get_color()); $elements[$i]->set_tooltip($unit . ": #val# " . $autorange[1]); if (sizeof($row) == 4) { $legend[] = $row[0]; } else { $legend[] = $row[0] . " -\n" . $row[1]; } $i++; } $bar = new bar_glass(); $bar->set_values($elements); $title = new title($title . " (" . $suffix . ")"); $title->set_style("{font-size: 18px; color: #444444; text-align: center;}"); $x_axis_labels = new x_axis_labels(); $x_axis_labels->set_size(10); $x_axis_labels->rotate(45); $x_axis_labels->set_labels($legend); $x_axis = new x_axis(); //$x_axis->set_3d( 3 ); $x_axis->set_colours('#909090', '#909090'); $x_axis->set_labels($x_axis_labels); $y_axis = new y_axis(); $y_axis->set_offset(true); $y_axis->set_colours('#909090', '#909090'); $y_axis->set_range(0, $maxvalue, $maxvalue / 10); $y_axis->set_label_text("#val# " . $autorange[1]); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); $chart->set_x_axis($x_axis); $chart->add_y_axis($y_axis); $chart->set_bg_colour('#FEFEFE'); echo $chart->toString(); } }
} $vid_line = new line(); $vid_line->set_values($vid_uploads); $vid_line->colour('#336600'); $vid_line->set_key('Videos', 14); $user_line = new line(); $user_line->set_values($user_signups); $user_line->colour('#0099cc'); $user_line->set_key('User', 14); $grp_line = new line(); $grp_line->set_values($groups_added); $grp_line->colour('#990000'); $grp_line->set_key('Groups', 14); $max = $max; $steps = round($max / 5, 0.49); $y = new y_axis(); $y->set_range(0, $max, $steps); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($vid_line); $chart->add_element($user_line); $chart->add_element($grp_line); $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_vertical(); $x_labels->set_colour('#A2ACBA'); $x_labels->set_labels($year); $x = new x_axis(); $x->set_colour('#A2ACBA'); $x->set_grid_colour('#D7E4A3'); $x->set_offset(false);
$tags->append_tag(new ofc_tag($x, $v->top, $statuscolor[$key])); $x++; } $bar = new bar_3d(); $bar->set_values(array_values($data)); $chart->add_element($bar); $chart->add_element($tags); //x-label $xal = new x_axis_labels(); $tmp = array(); foreach ($statustext as $status => $text) { $tmp[] = new x_axis_label($text, $statuscolor[$status], $xfs, 15); } $xal->set_labels($tmp); $xal->set_size($xfs); $x = new x_axis(); $x->set_offset(true); $x->set_labels($xal); $x->set_3d(5); $x->colour = '#909090'; $chart->set_x_axis($x); //y-label $yal = new y_axis_labels(); $yal->set_size($yfs); $y = new y_axis(); $y->set_labels($yal); $y->set_range(0, ceil($y_max / $step) * $step, $step); $chart->set_y_axis($y); //draw data for chart echo $chart->toString(); require_once 'confy_close.php';
$title = new title('Last ' . $days . ' Days Sales Chart'); $title->set_style("{font-size:14px; font-weight:bold; padding:10px;}"); $chart = new open_flash_chart(); $chart->set_title($title); $area = new area(); $area->set_colour('#5B56B6'); $area->set_values(array_values($bar_values)); $area->set_key('Products', 12); $chart->add_element($area); //define x-axis $x_labels = new x_axis_labels(); $x_labels->set_steps(4); $x_labels->set_labels($period); $x = new x_axis(); $x->set_grid_colour('#D7E4A3'); //$x->set_offset($period_offset); $x->set_steps(4); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); //define y-axis $y = new y_axis(); $range_min_value = 0; $range_max_value = max($bar_values); $y_data_step = ceil($range_max_value / $y_points); $y_data_step = $y_data_step - $y_data_step % 100; $range_max_value = ceil($range_max_value / $y_data_step) * $y_data_step; $y->set_range($range_min_value, $range_max_value, $y_data_step); $chart->add_y_axis($y); echo $chart->toPrettyString(); require_once 'confy_close.php';
/** * Build The 3-D Bar Gharph. * * @param array $params assoc array of name/value pairs * * @return object $chart object of open flash chart. * @static */ static function &bar_3dChart(&$params) { $chart = null; if (empty($params)) { return $chart; } // $params['values'] should contains the values for each // criteria defined in $params['criteria'] $values = CRM_Utils_Array::value('values', $params); $criterias = CRM_Utils_Array::value('criteria', $params); if (!is_array($values) || empty($values) || !is_array($criterias) || empty($criterias)) { return $chart; } // get the required data. $xReferences = $xValueLabels = $xValues = $yValues = array(); foreach ($values as $xVal => $yVal) { if (!is_array($yVal) || empty($yVal)) { continue; } $xValueLabels[] = (string) $xVal; foreach ($criterias as $criteria) { $xReferences[$criteria][$xVal] = (double) CRM_Utils_Array::value($criteria, $yVal, 0); $yValues[] = (double) CRM_Utils_Array::value($criteria, $yVal, 0); } } if (empty($xReferences)) { return $chart; } // get the currency. require_once 'CRM/Utils/Money.php'; $config = CRM_Core_Config::singleton(); $symbol = $config->defaultCurrencySymbol; // set the tooltip. $tooltip = CRM_Utils_Array::value('tip', $params, "{$symbol} #val#"); $count = 0; foreach ($xReferences as $criteria => $values) { $toolTipVal = $tooltip; // for seperate tooltip for each criteria if (is_array($tooltip)) { $toolTipVal = CRM_Utils_Array::value($criteria, $tooltip, "{$symbol} #val#"); } // create bar_3d object $xValues[$count] = new bar_3d(); // set colour pattel $xValues[$count]->set_colour(self::$_colours[$count]); // define colur pattel with bar criterias $xValues[$count]->key((string) $criteria, 12); // define bar chart values $xValues[$count]->set_values(array_values($values)); // set tooltip $xValues[$count]->set_tooltip($toolTipVal); $count++; } $chartTitle = CRM_Utils_Array::value('legend', $params) ? $params['legend'] : ts('Bar Chart'); //set y axis parameters. $yMin = 0; // calculate max scale for graph. $yMax = ceil(max($yValues)); if ($mod = $yMax % str_pad(5, strlen($yMax) - 1, 0)) { $yMax += str_pad(5, strlen($yMax) - 1, 0) - $mod; } // if max value of y-axis <= 0, then set default values if ($yMax <= 0) { $ySteps = 1; $yMax = 5; } else { $ySteps = $yMax / 5; } // create x axis label obj. $xLabels = new x_axis_labels(); $xLabels->set_labels($xValueLabels); // set angle for labels. if ($xLabelAngle = CRM_Utils_Array::value('xLabelAngle', $params)) { $xLabels->rotate($xLabelAngle); } // create x axis obj. $xAxis = new x_axis(); $xAxis->set_labels($xLabels); //create y axis and set range. $yAxis = new y_axis(); $yAxis->set_range($yMin, $yMax, $ySteps); // create chart title obj. $title = new title($chartTitle); // create chart. $chart = new open_flash_chart(); // add x axis w/ labels to chart. $chart->set_x_axis($xAxis); // add y axis values to chart. $chart->add_y_axis($yAxis); // set title to chart. $chart->set_title($title); foreach ($xValues as $bar) { // add bar element to chart. $chart->add_element($bar); } // add x axis legend. if ($xName = CRM_Utils_Array::value('xname', $params)) { $xLegend = new x_legend($xName); $xLegend->set_style("{font-size: 13px; color:#000000; font-family: Verdana; text-align: center;}"); $chart->set_x_legend($xLegend); } // add y axis legend. if ($yName = CRM_Utils_Array::value('yname', $params)) { $yLegend = new y_legend($yName); $yLegend->set_style("{font-size: 13px; color:#000000; font-family: Verdana; text-align: center;}"); $chart->set_y_legend($yLegend); } return $chart; }
include '../php-ofc-library/open-flash-chart.php'; $chart = new open_flash_chart(); $chart->set_title(new title('Area Chart')); // // Make our area chart: // $area = new area(); // set the circle line width: $area->set_width(2); $area->set_default_dot_style(new hollow_dot()); $area->set_colour('#838A96'); $area->set_fill_colour('#E01B49'); $area->set_fill_alpha(0.4); $area->set_values($data); // add the area object to the chart: $chart->add_element($area); $y_axis = new y_axis(); $y_axis->set_range(-2, 2, 2); $y_axis->labels = null; $y_axis->set_offset(false); $x_axis = new x_axis(); $x_axis->labels = $data; $x_axis->set_steps(2); $x_labels = new x_axis_labels(); $x_labels->set_steps(4); $x_labels->set_vertical(); // Add the X Axis Labels to the X Axis $x_axis->set_labels($x_labels); $chart->add_y_axis($y_axis); $chart->x_axis = $x_axis; echo $chart->toPrettyString();
/** * assign the chartdata object for open flash chart library * @param $config * @return unknown_type */ function _setChartdata($config) { $model = $this->getModel(); $rounds = $this->get('Rounds'); $round_labels = array(); foreach ($rounds as $r) { $round_labels[] = $r->name; } $division = $this->get('division'); $data = $model->getDataByDivision($division->id); //create a line $length = count($rounds) - 0.5; $linewidth = $config['color_legend_line_width']; $lines = array(); //$title = $division->name; $chart = new open_flash_chart(); //$chart->set_title( $title ); $chart->set_bg_colour($config['bg_colour']); //colors defined for ranking table lines //todo: add support for more than 2 lines foreach ($this->colors as $color) { foreach ($rounds as $r) { for ($n = $color['from']; $n <= $color['to']; $n++) { $lines[$color['color']][$n][] = $n; } } } //set lines on the graph foreach ($lines as $key => $value) { foreach ($value as $line => $key2) { $chart->add_element(hline($key, $length, $line, $linewidth)); } } //load team1, first team in the dropdown $team = $this->team1; $d = new $config['dotstyle_1'](); $d->size((int) $config['line1_dot_strength']); $d->halo_size(1); $d->colour($config['line1']); $d->tooltip('Rank: #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($team->rankings); $line->set_width((int) $config['line1_strength']); $line->set_key($team->name, 12); $line->set_colour($config['line1']); $line->on_show(new line_on_show($config['l_animation_1'], $config['l_cascade_1'], $config['l_delay_1'])); $chart->add_element($line); //load team2, second team in the dropdown $team = $this->team2; $d = new $config['dotstyle_2'](); $d->size((int) $config['line2_dot_strength']); $d->halo_size(1); $d->colour($config['line2']); $d->tooltip('Rank: #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($team->rankings); $line->set_width((int) $config['line2_strength']); $line->set_key($team->name, 12); $line->set_colour($config['line2']); $line->on_show(new line_on_show($config['l_animation_2'], $config['l_cascade_2'], $config['l_delay_2'])); $chart->add_element($line); $x = new x_axis(); if ($config['x_axis_label'] == 1) { $xlabels = new x_axis_labels(); $xlabels->set_labels($round_labels); $xlabels->set_vertical(); } $x->set_labels($xlabels); $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']); $chart->set_x_axis($x); $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_CURVE_ROUNDS')); $x_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_x_legend($x_legend); $y = new y_axis(); $y->set_range(count($data), 1, -1); $y->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']); $chart->set_y_axis($y); $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_CURVE_RANK')); $y_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_y_legend($y_legend); ob_clean(); echo $chart->toString(); }