This topic contains 4 replies, has 2 voices, and was last updated by  johnpapast 2 weeks, 4 days ago.

Pie Chart from php


  • johnpapast
    Participant

    Posts: 19
    Member Reply #19229

    Hello,

    I want to create charts from database with php.

    How can i achieve that?

    Thank you

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #19256

    Hi 🙂

    1) Using PHP, get the data from database. Keep the data in a variable.

    2) Get a sample chart code in javascript.

    3) Loop the data variable in PHP to construct a chart in javascript.

    You could give your code, we will guide you in the code.

    Thanks


    johnpapast
    Participant

    Posts: 19
    Member Reply #19272
    This reply has been marked as private.
    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #19317

    Hi 🙂

    You can take out <script src=”../assets/demo/default/custom/components/charts/amcharts/charts.js” type=”text/javascript”> as this file is a demo charts purpose only.

    For your case, you can do like this to insert the man and woman value to the javascript.

    <script>
        var chart = AmCharts.makeChart("chartdiv", {
            "type": "pie",
            "theme": "light",
            "dataProvider": [
                {
                    "gender": "Man",
                    "total": <?php echo $man_counter_records ?>
                }, {
                    "gender": "Woman",
                    "total": <?php echo $woman_counter_records ?>
                },
            ],
            "valueField": "total",
            "titleField": "gender",
            "balloon": {
                "fixedPosition": true
            },
            "export": {
                "enabled": true
            }
        });
    </script>

    Please check on this official documentation for more info about the charts;

    Simple Pie Chart

    Thanks


    johnpapast
    Participant

    Posts: 19
    Member Reply #19824

    Hello,

    I have follow your instructions and the pie chart is perfect.

    So, now i want a simple line chart for ages.

    Can you help me again?

    Thank you

Tagged: 

You must be logged in to reply to this topic.