Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Assign chart data

Questions related to using nuBuilder Forte.
Post Reply
Timo
Posts: 221
Joined: Thu Mar 15, 2018 9:26 pm
Has thanked: 1 time

Assign chart data

Unread post 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?
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: Assign chart data

Unread post 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
You do not have the required permissions to view the files attached to this post.
Timo
Posts: 221
Joined: Thu Mar 15, 2018 9:26 pm
Has thanked: 1 time

Re: Assign chart data

Unread post 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?
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: Assign chart data

Unread post 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
Timo
Posts: 221
Joined: Thu Mar 15, 2018 9:26 pm
Has thanked: 1 time

Re: Assign chart data

Unread post by Timo »

I see, thank you Steven.
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: Assign chart data

Unread post by admin »

.
Post Reply