Link to home
Start Free TrialLog in
Avatar of Moses Dwana
Moses Dwana

asked on

how to display the right hightchart category base on database value

hi guys, I am using hightchart libery to display data from my database into charts. i want to implement the following: fetch all departments and count how many time they are using the various conference rooms. (the three departments are: Administration, Health Services, Planning and the three conference rooms are: room227,room327 and room427)

the problem in the below script  is that, take for an example, i have only one entry for one department in the database which is Health Services, room327, if  this happen, the chart display  room227 to be the one that own the data because the category of the chart starts with room227.

the interpretation on the chart is  that room227 is the one that is booked , which is not the case in reality: in the database it shows that room327 is the one that is booked by Health Services.

see the script blow


            
	$sql21 = "SELECT count(room_id) as count1 FROM mohconferenceroom where department = ('ADM') GROUP BY (room_id) ORDER BY room_id";

	$viewer = mysqli_query($mysqli,$sql21);

	$viewer = mysqli_fetch_all($viewer,MYSQLI_ASSOC);

	$viewer = json_encode(array_column($viewer, 'count1'),JSON_NUMERIC_CHECK);
	
	
	


	

	$sql22 = "SELECT count(room_id) as count2 FROM mohconferenceroom where department = ('HSD') GROUP BY (room_id) ORDER BY room_id";

	$click = mysqli_query($mysqli,$sql22);

	$click = mysqli_fetch_all($click,MYSQLI_ASSOC);

	$click = json_encode(array_column($click, 'count2'),JSON_NUMERIC_CHECK);
	
	
	
	$sql23 = "SELECT count(room_id) as count3 FROM mohconferenceroom where department = ('PLA') GROUP BY (room_id) ORDER BY room_id";

	$consult = mysqli_query($mysqli,$sql23);

	$consult = mysqli_fetch_all($consult,MYSQLI_ASSOC);

	$consult = json_encode(array_column($consult, 'count3'),JSON_NUMERIC_CHECK);

Open in new window


the chart library
<script>
$(function () { 

    var data_viewer = <?php echo $viewer; ?>;
    var data_click = <?php echo $click; ?>;
   var data_consult = <?php echo $consult; ?>;
	 
	 
 $('#ratiobetween').highcharts({

        chart: {

            type: 'column'

        },

        title: {

            text: 'conference room usage per department'

        },

        xAxis: {

            categories: ['room227','room327','room427']

        },

        yAxis: {

            title: {

                text: 'Rate'

            }

        },

        series: [{

            name: 'Administration',
            data: data_viewer
			
            

        }, {

            name: 'Health Services',

           data: data_click
		    
        },{
		 name: 'Planning',
		 
		  data: data_consult
		  
		}]

    });

});


</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Only solution provided.