Welcome to the Simple Pie Chart Example

In this example we will be exploring the Simple Pie Chart using the php-d3-lib.

Pie Chart 1 (Autosized)

Pie Chart 1 PHP Code

*renders chart into element with id="chart"

        // if not already included, include the autoloader
        include('../PhpD3/autoloader.php');

        $data = array(
            'chart_data'=>array(
                array(
                    'label'=>'one',
                    'value'=>10
                ),
                array(
                    'label'=>'two',
                    'value'=>35
                ),
                array(
                    'label'=>'three',
                    'value'=>15
                ),
                array(
                    'label'=>'four',
                    'value'=>25
                ),
                array(
                    'label'=>'five',
                    'value'=>5
                )
            ),
            'dimensions'=>array(
                'height'=>500,
                'width'=>500,
                'radius'=>250
            ),
            'render_element'=>array(
                'value'=>'chart',
                'type'=>'id'
            ),
            'colors' => array(
                '#FF8E00',
                '#BF8030',
                '#A65C00',
                '#FFAA40',
                '#FFC173',
                '#a05d56',
                '#d0743c'
            ),
            'autosize' => true,
        );

        $chart = new PhpD3\Draw('simple_pie_chart',$data);
        $chart_render = $chart->render();

        echo $chart_render;

        


Pie Chart 2

Pie Chart 2 PHP Code

*renders chart into element with id="chart_2"

        // if not already included, include the autoloader
        include('../PhpD3/autoloader.php');

        $data_two = array(
            'chart_data'=>array(
                array(
                    'label'=>'six',
                    'value'=>20
                ),
                array(
                    'label'=>'seven',
                    'value'=>15
                ),
                array(
                    'label'=>'eight',
                    'value'=>30
                ),
                array(
                    'label'=>'nine',
                    'value'=>35
                ),
                array(
                    'label'=>'ten',
                    'value'=>10
                )
            ),
            'dimensions'=>array(
                'height'=>400,
                'width'=>400,
                'radius'=>200
            ),
            'render_element'=>array(
                'value'=>'chart_2',
                'type'=>'id'
            ),
            'colors' => array(
                '#98abc5',
                '#8a89a6',
                '#7b6888',
                '#6b486b',
                '#a05d56',
                '#d0743c',
                '#ff8c00'
            )
        );

        $chart_two = new PhpD3\Draw('simple_pie_chart',$data_two);
        $chart_two_render = $chart_two->render();

        echo $chart_two_render;