Example #1
0
 public function toObject()
 {
     $this->consolidateParameters();
     $xAxisLabels = new OFC_Elements_Axis_X_Label_Set();
     $xAxisLabels->set_labels($this->labels);
     $xAxisLabels->set_size(10);
     $xAxisLabels->set_colour('#444444');
     $xAxisLabels->set_steps($this->stepsX);
     $xAxis = new OFC_Elements_Axis_X();
     $xAxis->set_steps($this->stepsX);
     $xAxis->set_labels($xAxisLabels);
     $xAxis->set_colour('#CCCCCC');
     $xAxis->set_grid_colour('#AAAAAA');
     $this->chart->set_x_axis($xAxis);
     $yAxis = new OFC_Elements_Axis_Y();
     $yAxis->set_range($this->min1, $this->max1);
     $yAxis->set_colour('#AAAAAA');
     $yAxis->set_grid_colour('#AAAAAA');
     $yAxis->set_steps($this->stepsY1);
     $this->chart->set_y_axis($yAxis);
     $yLegend = new OFC_Elements_Legend_Y($this->data1->getName());
     //$this->chart->set_y_legend($yLegend); // does not work now
     // data 1
     $this->chart->add_element($this->createGraph($this->data1));
     if ($this->hasTwoDataLines()) {
         $yAxisRight = new OFC_Elements_Axis_Y_Right();
         $yAxisRight->set_range($this->min2, $this->max2);
         $yAxisRight->set_colour('#AAAAAA');
         $yAxisRight->set_steps($this->stepsY2);
         //            $this->chart->set_y_axis_right($yAxisRight);
         $this->chart->add_element($this->createGraph($this->data2));
     }
     return $this->chart;
 }
Example #2
0
/**
 * $array['title']
 * $array['legend_y']
 * $array['legend_x']
 * $array['values']
 * $array['values_key']
 * $array['range_max']
 * $array['range_step']
 * @param $array
 * @return unknown_type
 */
function create_chart_data($array)
{
    if (!$array) {
        return;
    }
    require_once 'OFC/OFC_Chart.php';
    $chart = new OFC_Chart();
    $chart->set_bg_colour('#ffffff');
    $title = new OFC_Elements_Title($array['title']);
    $title->set_style('{color: #567300; font-size: 16px; font-weight:bold;}');
    $chart->set_title($title);
    $yl = new OFC_Elements_Legend_Y($array['legend_y']);
    $yl->set_style('{font-size:18px;}');
    $chart->set_y_legend($yl);
    $xl = new OFC_Elements_Legend_X($array['legend_x']);
    $xl->set_style('{font-size:18px;color:#Ff0}');
    $chart->set_x_legend($xl);
    $elements = array();
    $colors = array('', '#CC00AA', '#9C48F0', '#b0de09', '#0d8ecf', '#ff6600', '#fcd202', '#E2EBFF', '#AAAAAA');
    foreach ($array['values'] as $k => $v) {
        ksort($v, SORT_STRING);
        $line = new OFC_Charts_Line();
        $line->set_key($array['values_key'][$k], 12);
        $colors[$k] ? $line->set_colour($colors[$k]) : '';
        $line->set_values(array_values($v));
        $default_dot = new OFC_Charts_Line_Dot();
        $default_dot->tooltip('#x_label#<br>#val#');
        $line->set_default_dot_style($default_dot);
        $elements[] = $line;
        $array['values'][$k] =& $v;
    }
    foreach ($elements as $element) {
        $chart->add_element($element);
    }
    $x = new OFC_Elements_Axis_X();
    $x->colour = '#909090';
    $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
    $x->set_steps($array['show_step']);
    $x_axis_labels->set_steps($array['show_step']);
    if (is_array($array['values'][0])) {
        $keys = array_keys($array['values'][0]);
    } else {
        $keys = array_keys($array['values']);
    }
    $x_axis_labels->set_labels($keys);
    $x_axis_labels->set_size(12);
    $x_axis_labels->set_colour('#Ff0');
    $x_axis_labels->set_rotate('-45');
    $x->set_labels($x_axis_labels);
    $chart->set_x_axis($x);
    $y = new OFC_Elements_Axis_Y();
    $range_min = isset($array['range_min']) ? $array['range_min'] : 0;
    $y->set_range($range_min, $array['range_max'], $array['range_step']);
    $chart->set_y_axis($y);
    return $chart->toPrettyString();
}