Sign in to follow this  
kbjayhawks

MySql Values with Array - Stacked Column

Recommended Posts

I'm sure I'm just missing something from a procedure standpoint, but I'm looking for some assistance in formatting the array string for a Stacked Column, where all data is derived from MySQL.

 

I've verified that my query is returning all the correct results and I can echo them all out independently....I just can't figure out the correct order to build the array to render the chart.  

 

Here's what I've got so far:

        	$categoryArray=array();
			$seriesnameArray=array();
			$seriesdataArray=array();

        	
        	while($row = mysqli_fetch_array($result)) {
								
									
				array_push($categoryArray, array(
					"label" => "YTD"
					)
				);

				array_push($seriesnameArray, array(
					$row["buying_channel"],
					"value" => $row["pct_of_incidents"]
					) 
				);
				
			//array_push($seriesdataArray, array(
			//		"value" => $row["pct_of_incidents"]
			//		) 
			//	);
			
    //    	}
        	
        	$arrData["categories"]=array(array("category"=>$categoryArray));
		
			
			$arrData["dataset"]=array(array("seriesname"=>$seriesnameArray));
			
		
		//	$arrData["data"]= array(array($seriesdataArray));
			

This produces the following array:

"data":[],"categories":[{"category":[{"label":"YTD"},{"label":"YTD"},{"label":"YTD"},{"label":"YTD"},{"label":"YTD"}]}],"dataset":[{"seriesname":[{"0":"In Club","value":"0.5192"},{"0":"Online","value":"0.4338"},{"0":"Transfer","value":"0.0263"},{"0":"Auction","value":"0.0117"},{"0":"Social Media","value":"0.0091"}]}]}

What I can't figure out is how to insert the "Data[]" attribute for each seriesname.  Currently it's producing a "0" value for each entry and I can't figure out where it's derived from.

 

Any insight would be greatly appreciated!

 

 

Thanks!

Share this post


Link to post
Share on other sites

Hi

 

You have to append categories array and array for series into one associative array which will have 3 objects i.e.

  • `chart` - it will have all chart config and cosmetic options,
  • `categories` - it will contain category object which will be x-axis labels and
  • `dataSet` - it will contain data arrays for different series.

After all these are ready you have to encode them to JSON to render the charts. You can refer to this link to download multi-series chart sample with PHP and MySQL: https://www.dropbox.com/s/82femvv3yqnddkc/multi-series-mysql.zip?dl=0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this