/** * Returns the data for a bar chart showing the amount of commits per author per hour of the day. * * @param sfWebRequest $request * * @return void */ public function executeChartAuthorActivityHours(sfWebRequest $request) { $scm_id = $this->getUser()->getSelectedScmId(); $username = $request->getParameter('param'); $query = Doctrine::getTable('Commit')->createQuery()->addWhere('scm_id = ?', $scm_id)->addWhere('author = ?', $username); $result = $query->fetchArray(); $hours = range(0, 23); $values = array_fill(0, 24, 0); foreach ($result as $item) { $hour = (int) date('H', strtotime($item['timestamp'])); $values[$hour]++; } //To create a bar chart we need to create a stBarOutline Object $bar = new stBarOutline(80, '#78B9EC', '#3495FE'); $bar->key('Commits per hour', 10); //Passing the random data to bar chart $bar->data = $values; //Creating a stGraph object $g = new stGraph(); $g->set_inner_background('#E3F0FD', '#CBD7E6', 90); $g->x_axis_colour('#8499A4', '#E4F5FC'); $g->y_axis_colour('#8499A4', '#E4F5FC'); //set background color $g->bg_colour = '#eeeeee'; //Set the transparency, line colour to separate each slice etc. $g->bar_filled(80, '#78B9EC', '#78B9EC', '{font-size: 12px; color: #78B9EC;'); //Pass stBarOutline object i.e. $bar to graph $g->data_sets[] = $bar; //Setting labels for X-Axis $g->set_x_labels($hours); // To tick the values on x-axis // 2 means tick every 2nd value $g->set_x_axis_steps(2); //set maximum value for y-axis //we can fix the value as 20, 10 etc. //but its better to use max of data $g->set_y_max(max($values)); $g->y_label_steps(4); $g->set_y_legend('# commits', 12, '#18A6FF'); //To display value as tool tip $g->set_tool_tip('#x_label#: #val# commits'); $g->title('Total commits per hour for ' . $username, '{font-size:18px; color: #18A6FF}'); return $this->renderText($g->render()); }