$data_1[] = rand(1, 6); $data_2[] = rand(7, 13); $data_3[] = rand(14, 19); } $line_dot = new OFC_Charts_Line_Dot(); $line_dot->set_width(4); $line_dot->set_colour('#DFC329'); $line_dot->set_dot_size(5); $line_dot->set_values($data_1); $line_hollow = new OFC_Charts_Line_Hollow(); $line_hollow->set_width(1); $line_hollow->set_colour('#6363AC'); $line_hollow->set_dot_size(5); $line_hollow->set_values($data_2); $line = new OFC_Charts_Line(); $line->set_width(1); $line->set_colour('#5E4725'); $line->set_dot_size(5); $line->set_values($data_3); $y = new OFC_Elements_Axis_Y(); $y->set_range(0, 20, 5); $chart = new OFC_Chart(); $chart->set_title(new OFC_Elements_Title('Three lines example')); $chart->set_y_axis($y); // // here we add our data sets to the chart: // $chart->add_element($line_dot); $chart->add_element($line_hollow); $chart->add_element($line); echo $chart->toPrettyString();
/** * @Route("/{anno}/{mes}/panel_proyeccion_nuevos_ingresos_marco_data.json", name="panel_proyeccion_nuevos_ingresos_marco_data", defaults={"anno"="2013","mes"="01"}, options={"expose"=true}) */ public function panelProyeccionNuevosIngresosMarcoAction($anno, $mes) { include_once __DIR__ . "/../Util/OFC/OFC_Chart.php"; $title = new \OFC_Elements_Title('Proyección ingresos por contratos marco ' . $anno); //Me conecto a la BD y pregunto por los ingresos del año: $ingresos = array(); //El primer indice lo lleno con ceros: foreach ($this->meses as $key => $value) { $ingresos[] = 0; } $sql = "SELECT MONTH(date_closed) as MES, SUM( CASE 1 WHEN ( (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) > 1) AND (opportunities_cstm.fecha_fin_contrato_c > '" . $anno . "-12-31')) THEN ROUND((amount * (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c)/DATEDIFF(opportunities_cstm.fecha_fin_contrato_c,opportunities_cstm.fecha_de_inicio_ejecucion_c))),2) WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) < 1) THEN 0 WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_fin_contrato_c) > -1) THEN amount END) as SUMA FROM opportunities INNER JOIN opportunities_cstm ON opportunities_cstm.id_c = opportunities.id WHERE deleted = 0 AND sales_stage = 'Closed Won' AND YEAR(date_closed) = " . $anno . " AND opportunities_cstm.contrato_marzo_c = 1 GROUP BY MES ORDER BY MES ASC;\n"; $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql); $stmt->execute(); foreach ($stmt->fetchAll() as $data) { $ingresos[$data["MES"] - 1] = (int) $data["SUMA"]; } $ingresos = array_slice($ingresos, 0, $mes); $this->acumulate($ingresos); $line_dot = new \OFC_Charts_Line(); $line_dot->set_values($ingresos); $line_dot->set_key("Ingresos", 10); $line_dot->set_width(1); $line_dot->set_colour('#FF0000'); $line_dot->set_dot_size(3); //Me conecto a la BD y pregunto por la proyeccion del año: $proyecciones = array(); //El primer indice lo lleno con ceros: foreach ($this->meses as $key => $value) { $proyecciones[] = 0; } $sql = "SELECT MONTH(date_closed) as MES, SUM( ( CASE 1 WHEN ( (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) > 1) AND (opportunities_cstm.fecha_fin_contrato_c > '" . $anno . "-12-31')) THEN ROUND((amount * (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c)/DATEDIFF(opportunities_cstm.fecha_fin_contrato_c,opportunities_cstm.fecha_de_inicio_ejecucion_c))),2) WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) < 1) THEN 0 WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_fin_contrato_c) > -1) THEN amount END) * IFNULL(probabiidad_adjudicacion_c/100,0) ) as SUMA FROM opportunities INNER JOIN opportunities_cstm ON opportunities_cstm.id_c = opportunities.id WHERE deleted = 0 AND sales_stage IN ('APROBADO','EN_ESTUDIO','PROSPECCION_CONTINGENTE','PROSPECCION_GENERAL') AND YEAR(date_closed) = " . $anno . " AND opportunities_cstm.contrato_marzo_c = 1 GROUP BY MES ORDER BY MES ASC;\n"; $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql); $stmt->execute(); foreach ($stmt->fetchAll() as $data) { $proyecciones[$data["MES"] - 1] = (int) $data["SUMA"]; } //La proyección del mes actual es la ultima de los ingresos. $proyecciones[$mes - 1] = $proyecciones[$mes - 1] + $ingresos[$mes - 1]; $this->acumulate($proyecciones); $line_dot_proyeccion = new \OFC_Charts_Line(); $line_dot_proyeccion->set_values($proyecciones); $line_dot_proyeccion->set_key("Estimado", 10); $line_dot_proyeccion->set_width(1); $line_dot_proyeccion->set_colour('#41DB00'); $line_dot_proyeccion->set_dot_size(3); //Metas $sql = "SELECT enero,febrero,marzo,abril,mayo,junio,julio,agosto,septiembre,octubre,noviembre,diciembre FROM metas_metas WHERE anno = 2013 AND deleted = 0 AND anno = " . $anno . " and es_marco = 1 LIMIT 1"; $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql); $stmt->execute(); $metas = array(0 => 0); foreach ($stmt->fetchAll() as $data) { $metas[0] = (int) $data["enero"]; $metas[1] = (int) $data["febrero"]; $metas[2] = (int) $data["marzo"]; $metas[3] = (int) $data["abril"]; $metas[4] = (int) $data["mayo"]; $metas[5] = (int) $data["junio"]; $metas[6] = (int) $data["julio"]; $metas[7] = (int) $data["agosto"]; $metas[8] = (int) $data["septiembre"]; $metas[9] = (int) $data["octubre"]; $metas[10] = (int) $data["noviembre"]; $metas[11] = (int) $data["diciembre"]; } $line_dot_metas = new \OFC_Charts_Line(); $line_dot_metas->set_values($metas); $line_dot_metas->set_key("Metas", 10); $line_dot_metas->set_width(1); $line_dot_metas->set_colour('#1240AB'); $line_dot_metas->set_dot_size(3); $x = new \OFC_Elements_Axis_X(); $x->set_labels_from_array($this->meses); $y = new \OFC_Elements_Axis_Y(); $max_avg = max($ingresos); $max_avg = $max_avg > max($proyecciones) ? $max_avg : max($proyecciones); $max = $max_avg > max($metas) ? $max_avg : max($metas); $max = round($max * 1.25, -3); $y->set_range(0, $max, round($max / 4, 0)); $chart = new \OFC_Chart(); $chart->set_bg_colour('#FFFFFF'); $chart->set_title($title); $chart->add_element($line_dot); $chart->add_element($line_dot_proyeccion); $chart->add_element($line_dot_metas); $chart->set_x_axis($x); $chart->set_y_axis($y); $response = new Response($chart->toPrettyString()); $response->headers->set('Content-Type', 'application/json'); return $response; }
function create_chart_data_object($type, $y_values_array) { switch ($type) { case 'line': $data_object = new OFC_Charts_Line(); if (array_var($y_values_array, 'color')) { $data_object->set_colour(array_var($y_values_array, 'color')); } if (array_var($y_values_array, 'dot_size')) { $data_object->set_dot_size(array_var($y_values_array, 'dot_size')); } if (array_var($y_values_array, 'halo_size')) { $data_object->set_halo_size(array_var($y_values_array, 'halo_size')); } if (array_var($y_values_array, 'text')) { $data_object->set_key(array_var($y_values_array, 'text', ''), array_var($y_values_array, 'text_size', 10)); } if (array_var($y_values_array, 'width')) { $data_object->set_width(array_var($y_values_array, 'width')); } $values_data = array_var($y_values_array, 'values', array()); break; case 'bar': $data_object = new OFC_Charts_Bar_3d(); if (array_var($y_values_array, 'color')) { $data_object->set_colour(array_var($y_values_array, 'color')); } if (array_var($y_values_array, 'tooltip')) { $data_object->set_tooltip(array_var($y_values_array, 'tooltip')); } if (array_var($y_values_array, 'text')) { $data_object->set_key(array_var($y_values_array, 'text', ''), array_var($y_values_array, 'text_size', 10)); } if (array_var($y_values_array, 'alpha')) { $data_object->set_alpha(array_var($y_values_array, 'alpha')); } $values_data = array_var($y_values_array, 'values', array()); break; case 'bar-stack': $data_object = new OFC_Charts_Bar_Stack(); if (array_var($y_values_array, 'color')) { $data_object->set_colour(array_var($y_values_array, 'color')); } if (array_var($y_values_array, 'colors')) { $data_object->{'colours'} = array_var($y_values_array, 'colors'); } if (array_var($y_values_array, 'keys')) { $data_object->{'keys'} = array_var($y_values_array, 'keys'); } if (array_var($y_values_array, 'tooltip')) { $data_object->set_tooltip(array_var($y_values_array, 'tooltip')); } if (array_var($y_values_array, 'text')) { $data_object->set_key(array_var($y_values_array, 'text', ''), array_var($y_values_array, 'text_size', 10)); } if (array_var($y_values_array, 'alpha')) { $data_object->set_alpha(array_var($y_values_array, 'alpha')); } $data = array_var($y_values_array, 'values', array()); foreach ($data as $d) { $data_object->append_stack($d); } break; default: continue; } if (isset($values_data)) { $data_object->set_values($values_data); } return $data_object; }
private function createGraph(Gpf_Chart_DataRecordSet $data) { if ($this->chartType == Gpf_Rpc_Chart::CHART_TYPE_LINE_DOT && $this->data1->getSize() > 150) { $this->chartType = Gpf_Rpc_Chart::CHART_TYPE_LINE; } switch ($this->chartType) { case Gpf_Rpc_Chart::CHART_TYPE_AREA: if ($data->getSize() > 40) { $areaGraph = new OFC_Charts_Area_Line(); } else { $areaGraph = new OFC_Charts_Area_Hollow(); } $areaGraph->set_width(3); $areaGraph->set_dot_size(3); $areaGraph->set_colour($data->getColor()); $areaGraph->set_key($data->getName(), 10); $areaGraph->set_values($data->getValues()); $areaGraph->set_tooltip($data->getTooltip()); return $areaGraph; case Gpf_Rpc_Chart::CHART_TYPE_BAR_OUTLINE: $barGraph = new OFC_Charts_Bar(); $barGraph->set_alpha(50); $barGraph->set_colour($data->getColor()); $barGraph->set_key($data->getName(), 10); $barGraph->set_values($data->getValues()); $barGraph->set_tooltip($data->getTooltip()); return $barGraph; case Gpf_Rpc_Chart::CHART_TYPE_LINE_DOT: $lineDotGraph = new OFC_Charts_Line_Dot(); $lineDotGraph->set_width(3); $lineDotGraph->set_dot_size(3); $lineDotGraph->set_colour($data->getColor()); $lineDotGraph->set_key($data->getName(), 10); $lineDotGraph->set_values($data->getValues()); $lineDotGraph->set_tooltip($data->getTooltip()); return $lineDotGraph; default: $lineGraph = new OFC_Charts_Line(); $lineGraph->set_width(3); $lineGraph->set_dot_size(3); $lineGraph->set_colour($data->getColor()); $lineGraph->set_key($data->getName(), 10); $lineGraph->set_values($data->getValues()); $lineGraph->set_tooltip($data->getTooltip()); return $lineGraph; } }