How to Display Data In Pie Chart Using PHP And jQuery

In this post we will make simple pie chart by using Google chart library with php script and mysql database. This advance topic in web development with php programming. For making pie chart we will use Google chart library for making pie chart and we have pass mysql data by using php programming in json format. You may also like Multiple file upload in Codeigniter and curl request in udemy api using php

PHP Code

$rating_data = array(
    array('Employee', 'Rating'),
    array('Suresh', 20),
    array('Amit', 56),
    array('Mitul', 56),
    array('Rahul', 37),
$encoded_data = json_encode($rating_data);

HTML & jQuery Code

        <script type="text/javascript" src=""></script>
        <script type="text/javascript" src=""></script>
        <script type="text/javascript">
            google.load("visualization", "1", {packages: ["corechart"]});
            function drawChart()
                var data = google.visualization.arrayToDataTable(
                <?php echo $encoded_data; ?>
                var options = {
                    title: "Employee Ratings"
                var chart = new google.visualization.PieChart(document.getElementById("employee_piechart"));
                chart.draw(data, options);
        <div id="employee_piechart" style="width: 900px; height: 500px;"></div>

Leave a Reply

Your email address will not be published. Required fields are marked *