Any idea how to turn on stacking for bar/column charts? It's possible in both Google (https://developers.google.com/chart/interactive/docs/gallery/columnchart...) and Highcharts (http://www.highcharts.com/demo/column-stacked). Looking through the API I thought it would be straightforward to override defaults, but the following has no effect:

function MYMODULE_charts_type_info_alter(&$chart_types) {
  $chart_types['column']['stacking'] = TRUE;
}

Any other thoughts?

It would be nice if it was a configurable option in the View > Chart > Settings... but that's another problem.

Comments

timdavison’s picture

I think you need hook_chart_alter e.g.

function MYMODULE_chart_alter(&$chart, $chart_id) {

$chart['#stacking'] = true;
}

You can use the $chart_id to check it's the right chart to alter if you have more than one.

Pierre.Vriens’s picture

Thanks Tim for the suggestion about what might possibly be a solution for this issue. Hopefully Rob will further update the issue with the results after using your suggestion (i.e.: did it work?).

Note the parent issue I also added here ...

robcarr’s picture

Status: Active » Fixed

Worked for me.

Used following to ID and target specific charts:

function MYMODULE_chart_alter(&$chart, $chart_id) {
  dsm($chart_id); // Need Developer module enabled for dsm to work
  if ($chart_id == 'MYCHARTVIEW__DISPLAY') { // Watch out for those double underscores
    $chart['#stacking'] = TRUE;
  }
}

Thanks @timdavison for your help. Sorry for delay in reply - Christmas and house move got in the way

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

funkeyrandy’s picture

how would this be added to the views chart types? I need a stacking chart generated from views

funkeyrandy’s picture

never mind...accomplished with a module

katrien_w’s picture

@funkeyrandy: can you please share which module you accomplished this with?

funkeyrandy’s picture

i just made a custom module like in #3

<?php
function MYMODULE_chart_alter(&$chart, $chart_id) {
  dsm($chart_id); // Need Developer module enabled for dsm to work
  if ($chart_id == 'MYCHARTVIEW__DISPLAY') { // Watch out for those double underscores
    $chart['#stacking'] = TRUE;
  }
}
?>