function render_pie_chart($options) { $values = array(); $colours = array(); if (is_array($options['data'])) { foreach ($options['data'] as $data) { // $values[] = new OFC_Charts_Pie_Value($data['value'], $data['text']) ; $value = new OFC_Charts_Pie_Value($data['value'], $data['text']); $value->label = $data['text']; $values[] = $value; $colours[] = $data['color']; } } $chart = new OFC_Chart(); $chart->set_bg_colour(array_var($options, 'background-color', '#FFFFFF')); $chart->set_title(new OFC_Elements_Title(array_var($options, 'title', ""))); $pie = new OFC_Charts_Pie(); if (array_var($options, 'start_angle')) { $pie->set_start_angle(array_var($options, 'start_angle')); } $pie->tip = array_var($options, 'tip') ? array_var($options, 'tip') : "#val#/#total#<br>#percent#"; $pie->values = $values; $pie->colours = $colours; $pie->alpha = array_var($options, 'alpha') ? array_var($options, 'alpha') : 0.7; $pie->set_animate(array_var($options, 'animate', true)); $chart->add_element($pie); $chart->x_axis = null; $filename = 'tmp/' . gen_id() . '.json'; file_put_contents(ROOT . "/{$filename}", $chart->toPrettyString()); open_flash_chart_object(array_var($options, 'width'), array_var($options, 'height'), ROOT_URL . "/{$filename}", gen_id()); }
* License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(OFC_LIBRARY_PATH . '/lib/OFC/OFC_Chart.php'); $title = new OFC_Elements_Title( 'Area Chart' ); $pie = new OFC_Charts_Pie(); $pie->set_start_angle( 35 ); $pie->set_animate( true ); $chart = new OFC_Chart(); $chart->set_title( $title ); $chart->add_element( $pie ); $chart->x_axis = null; echo $chart->toPrettyString();
/** * @Route("/{anno}/{mes}/panel_lost_in_progress_data.json", name="panel_lost_in_progress_data", defaults={"anno"="2013","mes"="01"}, options={"expose"=true}) */ public function panelLostInProgressDataAction($anno, $mes) { include_once __DIR__ . "/../Util/OFC/OFC_Chart.php"; $title = new \OFC_Elements_Title(' '); $sql = "SELECT rechazo_otros_c , rechazo_por_calif_tecnica_c , rechazo_por_precio_c, rechazo_por_retraso_c , rechazo_por_tiempo_de_ejecu_c FROM opportunities INNER JOIN opportunities_cstm ON opportunities_cstm.id_c = opportunities.id WHERE opportunities.sales_stage = 'Closed Lost' AND YEAR(date_closed) = " . $anno . " AND deleted = 0;"; $dataPie = array(); $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql); $stmt->execute(); $items = $stmt->fetchAll(); $total = 0; $info = array('rechazo_sin_especificar_c' => array('SUMA' => 0, 'ITEM' => 'SIN ESPECIFICAR'), 'rechazo_otros_c' => array('SUMA' => 0, 'ITEM' => 'OTRAS'), 'rechazo_por_calif_tecnica_c' => array('SUMA' => 0, 'ITEM' => 'CALIFICACIÓN TÉCNICA'), 'rechazo_por_precio_c' => array('SUMA' => 0, 'ITEM' => 'PRECIO'), 'rechazo_por_retraso_c' => array('SUMA' => 0, 'ITEM' => 'RETRASO'), 'rechazo_por_tiempo_de_ejecu_c' => array('SUMA' => 0, 'ITEM' => 'TIEMPO DE EJECUCIÓN')); foreach ($items as $data) { //SI NO SE ESPECIFICA ES "SIN ESPECIFICAR" if ((int) $data['rechazo_por_calif_tecnica_c'] + (int) $data['rechazo_por_retraso_c'] + (int) $data['rechazo_por_tiempo_de_ejecu_c'] + (int) $data['rechazo_por_precio_c'] + (int) $data['rechazo_otros_c'] == 0) { $info['rechazo_sin_especificar_c']['SUMA'] = $info['rechazo_sin_especificar_c']['SUMA'] + 1; } $info['rechazo_otros_c']['SUMA'] = $info['rechazo_otros_c']['SUMA'] + (int) $data['rechazo_otros_c']; $info['rechazo_por_calif_tecnica_c']['SUMA'] = $info['rechazo_por_calif_tecnica_c']['SUMA'] + (int) $data['rechazo_por_calif_tecnica_c']; $info['rechazo_por_precio_c']['SUMA'] = $info['rechazo_por_precio_c']['SUMA'] + (int) $data['rechazo_por_precio_c']; $info['rechazo_por_retraso_c']['SUMA'] = $info['rechazo_por_retraso_c']['SUMA'] + (int) $data['rechazo_por_retraso_c']; $info['rechazo_por_tiempo_de_ejecu_c']['SUMA'] = $info['rechazo_por_tiempo_de_ejecu_c']['SUMA'] + (int) $data['rechazo_por_tiempo_de_ejecu_c']; } foreach ($info as $data) { $total = $total + $data['SUMA']; } foreach ($info as $data) { $dataPie[] = new \OFC_Charts_Pie_Value(round(100 * (int) $data["SUMA"] / $total, 0), ucfirst(strtolower($data["ITEM"])) . ' (' . round(100 * (int) $data["SUMA"] / $total, 0) . '%)'); } $bar = new \OFC_Charts_Pie(); $bar->set_start_angle(0); $bar->values = array_values($dataPie); $chart = new \OFC_Chart(); $chart->set_bg_colour('#FFFFFF'); $chart->set_title($title); $chart->add_element($bar); $response = new Response($chart->toPrettyString()); $response->headers->set('Content-Type', 'application/json'); return $response; }