KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Mysql query to be used with line chart. #1726

Open Kevin opened this topic on on Nov 22, 2020 - 1 comments

Kevin commented on Nov 22, 2020

I'm trying to figure out the magic to create a line chart from database. I cant seem to figure the magic json format to use. The example shows this data. I have created tables in the database to replicate this data, but I cant figure out the steps to get it from a mysql table into a datastore in the same format that the command below does it.

ANy help with be apprciated.

$category_amount = array(
    array("category"=>"Books","sale"=>32000,"cost"=>20000,"profit"=>12000),
    array("category"=>"Accessories","sale"=>43000,"cost"=>36000,"profit"=>7000),
    array("category"=>"Phones","sale"=>54000,"cost"=>39000,"profit"=>15000),
    array("category"=>"Movies","sale"=>23000,"cost"=>18000,"profit"=>5000),
    array("category"=>"Others","sale"=>12000,"cost"=>6000,"profit"=>6000),
);

<?php
Line::create(array(
    "dataSource"=>$category_amount,
    "columns"=>array(
        "category",
        "sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
        "cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
        "profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
    )
));
?>
David Winterburn commented on Nov 23, 2020

Hi Kevin,

In case your chart widget's data source is an array and not a datastore or a function, please use the "data" property instead of "dataSource":

    LineChart::creata(array(
        "data" => $chartArray,
        ...
    ));

Let us know how it works for you. Thanks!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None