Page 1 of 1

Assign chart data

Posted: Thu Mar 22, 2018 8:16 pm
by Timo
How display a Chart Type "Bar Graph - Horizontal) using a query?

Code: Select all

SELECT cust_reason, count(cust_reason) as total 
FROM customers _data
WHERE DATE(cus_created) = CURDATE() 
GROUP BY cust_reason
Can I use nuRunQuery and assign its output to a Javascript Array?

Re: Assign chart data

Posted: Fri Mar 23, 2018 3:17 am
by admin
Timo,

You can do this on Before Edit.

Code: Select all

$a[] = ['State', 'Jan', 'Feb', 'Mar'];
$s   = "SELECT  state, SUM(jan_sales), SUM(feb_sales), SUM(march_sales) FROM dataset GROUP BY state";
$t   = nuRunQuery($s);

while($r = db_fetch_row($t)){
    $a[] = [$r[0], floatval($r[1]), floatval($r[2]), floatval($r[3])];
}

$j   = "window.gdata = " . json_encode($a) . ";";

nuAddJavascript($j);

Then you can use window.gdata in your Chart...
hchart.PNG
Steven

Re: Assign chart data

Posted: Fri Mar 23, 2018 10:53 pm
by Timo
Thank you so much. One more question: If I use more than one chart, how do I assign data to window.gdata? Is there a window.gdata2 etc?

Re: Assign chart data

Posted: Sat Mar 24, 2018 1:37 am
by admin
Timo,

I think I understand your question, so let me say,

window.gdata is just a random variable I made up.

It is essentially a global variable that can be used anywhere.

I called it gdata, but you can call it whatever you want.


Steven

Re: Assign chart data

Posted: Mon Mar 26, 2018 2:15 pm
by Timo
I see, thank you Steven.

Re: Assign chart data

Posted: Mon Mar 26, 2018 11:38 pm
by admin
.