Jump to content

Recommended Posts

I'm still trying to figure JPGraph out, and am currently stuck on this problem. I want a user to select a month on a drop down, then display a graph of the four weeks of the month containing the sales information. Here's the code I have for a Yearly by Month graph. What would I need to change to accomplish this? Thanks everyone!

 

<? ini_set("display_errors","on"); ?>
<? require_once("../../wwwroot/conduit/crm.php"); ?>
<? $rpt_date = (isset($_GET['rpt_date']) ? $_GET['rpt_date'] : date("Y")); ?>
<? require_once ("jpgraph/jpgraph.php"); ?>
<? require_once ("jpgraph/jpgraph_bar.php"); ?>
<?
$bar_width = 50;

// Graph Monthly Sales for the 
$query = "SELECT date_format(date,'%b') as month_name, salesperson, round(sum(amount),2) as total_sales FROM crm.finance where left(date,4) = '$rpt_date' and salesperson = 'xxxx' group by left(date,7)";

$result = mysql_query($query);
$count = mysql_num_rows($result);
$data = mysql_fetch_assoc($result);

	// Load the Daily Sales Array
do
	{
		$monthly_totals[] = $data['total_sales'];
		$monthly_totals_label[] = $data['month_name'];
	} while ($data = mysql_fetch_assoc($result)); ?>
<?
// Create NEW Bar Graph
$graph = new Graph(1100,500,'auto');										// Initialize the graph
$graph->SetShadow();																		// Set a shadow on the graph page
$graph->SetScale("textlin");														// Set the x,y scale, x=text, y=lin
$graph->xaxis->SetTickLabels($monthly_totals_label);			// Load the x-axis tick labels
$graph->xaxis->SetFont(FF_FONT1);												// Set the font for the ticks
$graph->yaxis->scale->SetGrace(15,0);										// Add 15% top room for bar labels
$graph->title->Set("Monthly Sales by Year for Meredith Greenwood");							// Set Graph Title
$graph->xaxis->SetTitle("Months of the Year",'middle');	// Set x-axis Title
$graph->title->SetFont(FF_FONT1,FS_BOLD);								// Set Title Font, Style
$graph->legend->SetPos(0.0,0.0,'left','top');						// Position the Legend
if (count($monthly_totals_label) > 12):													// Skip tick labels if plotting more than 15 items
	$graph->xaxis->SetTextLabelInterval(2);
endif;

// Data Set 1, Total Sales, Group 1
$b1 = new BarPlot($monthly_totals);												// Plot the dataset
$b1->SetWidth($bar_width);															// Set bar width to 10
$b1->value->SetFormat('$%.2f');													// Format the Bar Value Labels $0.00
$b1->SetLegend("Total Sales in $$");										// Set the Legend line for Data Set 1
$b1->value->show();																			// Show bar values
$b1->SetFillColor('AntiqueWhite3');											// Set bar fill color
  $b1->value->SetFont(FF_ARIAL,FS_BOLD,10);								// Set bar value font
  $b1->value->SetAngle(0);																// Set bar value text angle
// $b1->SetValuePos('right');															// Set bar value position


// Group the different datasets together.
$gbplot = new GroupBarPlot(array($b1));

// Display Values in Bars

// The order the plots are added determines who's ontop
$graph->Add($gbplot);

// Finally output the  image
$graph->Stroke();
?>

Link to comment
https://forums.phpfreaks.com/topic/87135-solved-monthly-by-weeks-in-jpgraph/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.