I'm using this great module for my reviews site. I am trying to create a horizontal bar graph showing how many 1star, 2star etc reviews there are on each product, just like Amazon does.

1) I am trying to set the bottom axis to the size of the total amount of reviews. I.e., lets say this product has five 1star reviews, five 2star reviews, five 3star, 4star and 5star reviews - so every star amount has exactly five reviews. On the standard horizontal graph, all five bars will extend to the end of the graph, which I do not want. The bottom axis should be set to 25, being that there are 25 reviews in total. How do I set the bottom axis to a number, thereby ensuring that the bars only extend to the 5 mark and not further?

2) Is it possible to get rid of the x and y axis lines the graph draws?

3) Is it possible to position one set of bars directly behind another set of smaller bars, or can they only be side by side?

Thanks!

Current code

$chart = array(
      '#chart_id' => 'tally',
      '#type' => CHART_TYPE_BAR_H_GROUPED,
      '#size' => chart_size(60, 100),
      '#bar_size' => chart_bar_size(13, 2),
      '#adjust_resolution' => TRUE, 
    );
    
  $chart['#data'][] = array($tally['100']); // $tally['100'] is total amount of 5star reviews
  $chart['#data'][] = array($tally['80']);  / $tally['80'] is total amount of 4star reviews, etc
  $chart['#data'][] = array($tally['60']);
  $chart['#data'][] = array($tally['40']);
  $chart['#data'][] = array($tally['20']); 
  
  $chart['#data_colors'][] = 'ffcc66';

print '<div>';
  echo chart_render($chart);
print '</div>';

Comments

ylesches’s picture

I've figured out problem 1 above with the jwinstanley's patch.

Anyone know if there is a way to remove the axis lines?

13rac1’s picture

Status: Active » Closed (fixed)

2.) chxs/#mixed_axis_label_styles can control the label styles. You can try it on: http://imagecharteditor.appspot.com/ Create an axis, and select "Invisible Axis Line". More information here in the Google Chart Docs: http://code.google.com/apis/chart/image/docs/chart_params.html#axis_labe...

3.) Yes: http://chart.apis.google.com/chart?chxr=0,0,160&chxt=x&chbh=a&chs=440x22...|50,60,100,40,30,40,30&chtt=Horizontal+bar+chart

Re-open if needed...

Pierre.Vriens’s picture

Pierre.Vriens’s picture

Title: Copying amazon » HowTo show horizontal bar chart for ratings (as on Amazon)

Adapting title to link to this issue from the Chart HowTos docu ...