Reportes gráficos en Yii

| 2014-01-17 | 0 Comments

Una utilidad muy grande es crear reportes gráficos, sirve mucho por ejemplo para ver todo lo que se facturó en un mes o cuestiones similares.

Cuando estuve realizando mi proyecto, utilicé la siguiente extensión: eflot yii para crear reportes gráficos de forma personalizada.

Lo único que deben de hacer es descargar y agregar dicha extensión al directorio: /protected/extensions.

Ejemplo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<h1>Flot</h1>
<?php
// lines and bars in same graph
 
$this->widget('application.extensions.EFlot.EFlotGraphWidget',
    array(
        'data'=>array(
            array(
                'label'=> 'line',
                'data'=>array(
                    array(1,1),
                    array(2,7),
                    array(3,12),
                    array(4,32),
                    array(5,62),
                    array(6,89),
                ),
                'lines'=>array('show'=>true),
                'points'=>array('show'=>true),
            ),
            array(
                'label'=> 'bars',
                'data'=>array(
                    array(1,12),
                    array(2,16),
                    array(3,89),
                    array(4,44),
                    array(5,38),
                ),
                'bars'=>array('show'=>true),
            ),
        ),
        'options'=>array(
                'legend'=>array(
                    'position'=>'nw',
                    'show'=>true,
                    'margin'=>10,
                    'backgroundOpacity'=> 0.5
                    ),
        ),
        'htmlOptions'=>array(
               'style'=>'width:400px;height:400px;'
        )
    )
);
?>
 
//Pie chart example
 
<?php
$format_func = <<<EOD
js:function(label, series){
    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';}
EOD;
$this->widget('application.extensions.EFlot.EFlotGraphWidget',
    array(
        'data'=>array(
            array('label'=>'cows', 'data'=>20),
            array('label'=>'sheep', 'data'=>20),
            array('label'=>'chickens', 'data'=>30),
        ),
        'options'=>array(
            'series'=> array('pie'=>array(
                'show'=>true,
                'radius'=> 3/4,
                'formatter'=> $format_func,
                ),
            ),
            'legend'=> array('show'=>false),
        ),
        'htmlOptions'=>array('style'=>'width:400px;height:400px;')
    )
);
?>

Acerca del autor: Rodrigo Paszniuk

Ingeniero Informático, amante de la tecnología, la música, el ciclismo y aprender cosas nuevas.

Posts Relacionados

  • Backup en Yii
  • Manual intermedio de Yii framework (PHP)
  • Maestro-Detalle / Factura Compra en Yii – Parte II
  • Maestro-Detalle / Factura Compra en Yii – Parte I



SEGUÍNOS EN FACEBOOK


GITHUB