This article will show how to create a mySQL driven line chart using Charts 4 PHP Framework.

Step 1: Configure Database connectivity in config.php


Step 2: Include Charts 4 PHP Library

$p = new chartphp();

Step 3: Configure Data array using jQuery to fetch data from Database

'.wch_stripslashes('$p->data_sql = "select strftime('%Y-%m',o.orderdate) as Year, sum(d.quantity) as Sales 
                    from `order details` d, orders o 
                    where o.orderid = d.orderid 
                    group by strftime('%Y-%m',o.orderdate) limit 50";

Step 4: Set Chart type

'.wch_stripslashes('$p->chart_type = "line";

Step 5: Render Chart

'.wch_stripslashes('$out = $p->render("c1");

For complete code, please visit live demo.