Hi,

Great module. I couldn't figure out a way to implement the "stacked : true" option.

For example, there's a stacked bar chart, on the example page:
http://g.raphaeljs.com/barchart2.html

The code for it is:

r.hbarchart(330, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], {stacked: true}).hover(fin, fout);

And I'm trying to create something similar, like this:

      $graphael = array(
        'method' => 'hbar',
        'values' => $values,
        'params' => array(
          'opts' => array(
            'stacked' => TRUE,
          ),
        ),
      );

  return theme('graphael', $graphael);

Am I missing something? Or does the module just not support this yet?

Thanks,

Comments

sebsebseb123’s picture

Title: Support for "stacked = true" option. » Single value thermometer style graph... tips?
Category: feature » support

...turns out the 'stacked' option IS supported. I'm just not implementing it properly.

I needed to change the order of the array so that the different values are associated with each other.

This is what I had:

  $goal = 300;
  $count = 123;

  $values = array($goal, $count);

But this is what I need:

  $goal = 300;
  $count = 123;

  $values = array(
    0 => array(
      0 => $goal,
    ),
    1 => array(
      0 => $count,
    ),
  );

This is not longer an issue but I would love some help with my use case.

I'm trying to create a thermometer style single bar. I misunderstood what 'stacked' does. So, I'm now calculating the remainder value... the value needed to make the "thermometer" full and stacking those onto each other... so my final code looks like this:


      // We need to get the remainder of ($goal - $count)
      $values[1] = $values[1] - $values[0];
      
      // Change order of array so that elements stack onto each other
      $values = array(
        0 => array(
          0 => $values[0],
        ),
        1 => array(
          0 => $values[1],
        ),
      );

      $graphael = array(
        'method' => 'hbar',
        'values' => $values,
        'params' => array(
          'opts' => array(
            'stacked' => TRUE,
          ),
        ),
      );

  return theme('graphael', $graphael);

"Works"... except now I'm setting the colour of the "remainder" value to be white. Now the final part I'm missing is a border around that column.

Is there a good way to do this? Or, is there a better way to do single value thermometer style bar graphs?