Chart under table in table view

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Chart under table in table view

Post by SkayyHH » 2022-03-06 11:24

Hi,

I'm looking for a simple solution to display a bar chart with the data from the actual table view under the table in table view.

E.g. I have fields for status. The choice is high, medium, low. Now I just want a chart under the table that shows how many entries each with high, medium, low are displayed in the table.

Which tool is best suited for this? Chart.js? Or is that already possible with the AppGini Summary Reports plugin?

I would be very happy about an example if someone has already done it this way.

Thank you very much!

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Chart under table in table view

Post by pbottcher » 2022-03-06 20:03

Hi,

using chartist you can have a simple example like:

in your hooks / TABLENAME.php -> TABLENAME_header function try this:

Code: Select all

			case 'tableview':
			$sql="SELECT FIELDSTATUS, count(FIELDSTATUS) FROM `TABLENAME` group by FIELDSTATUS";
			$res=sql($sql,$eo);
			while ($row=db_fetch_row($res)) {
				$data[$row[0]]=$row[1];
			}
			
				$header='<%%HEADER%%><link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css"><script src="https://cdnjs.cloudflare.com/ajax/libs/chartist/0.11.4/chartist.min.js"></script><script>
						$j(function() {
							var cn=\'<div class="ct-chart ct-perfect-fourth"></div>\';
							$j(".table-responsive").append(cn);
							new Chartist.Bar(\'.ct-chart\',
								{
								  labels: [\''.implode("','",array_keys($data)).'\'],
								  series: [['.implode(",",array_values($data)).']]
								}, 
								{
									  width: 800,  // <--  adjust your settings
									  height: 300
								}
							);
						});
				</script>';
You need to play around with the different options, like colors etc. But I leave that up to you :-)
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-06 20:06

Thank you very much! I will try it :-)

Many greetings, Kai

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-06 20:23

i got it 1000 x thanks! I've been trying for days but can't get it by myself.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-06 20:31

The chart shows the result of all data sets. Can I also limit the chart to the filtered view?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Chart under table in table view

Post by pbottcher » 2022-03-06 21:00

Sure,

just add a where clause in the SQL statement

SELECT FIELDSTATUS, count(FIELDSTATUS) FROM `TABLENAME` WHERE WHERECLAUSE group by FIELDSTATUS

You need to check what the parameters are $_REQUEST will show them. Also you might need to know how many records are shown, if you want to display the graph to the amount of records shown in the TV. But this you need to know and hard code as there is no variable to my knowledge that you might access.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-06 21:28

How am I supposed to do that?

I.E. if someone uses the quick search field to filter, I don't know how many records the result is.

Or have I thought incorrectly about that?

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-07 06:20

One problem more with that ;-)

I need to select only records from actual logged in member. The chart shows the result from all records in database.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Chart under table in table view

Post by pbottcher » 2022-03-07 07:09

Hi,

well all this needs to be handled with the SQL query (the sample was just high level). You need to set-up the query to your needs.
The $_REQUEST array gives you all the needed data for the request itself, like filter, searchstring, catch the memberinfo via the getMemberInfo call.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-07 07:22

Thank you very much. I will try to find out the $_REQUEST parameters.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-07 22:17

Unfortunately I can't do it. I've been trying all day. With your code I get the chart evaluation of all data sets. This works well.

But i need the counts from the current view not all records in database.

I don't know what kind of $_REQUEST parameter I need and unfortunately also not how to build it into the SQL select :-(

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Chart under table in table view

Post by pbottcher » 2022-03-08 07:46

Hi,

as this depends completely on your app it is not possible to provide more than the generic help here. If you need further coding support, please look for a coder to help you.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Chart under table in table view

Post by SkayyHH » 2022-03-08 11:17

Ok, and thanks much for your help!

Post Reply