chartist icon indicating copy to clipboard operation
chartist copied to clipboard

Question: Stacked Bar Labels

Open mturnwall opened this issue 11 years ago • 8 comments

Is there a way to place labels on top of the stacked bars?

image

mturnwall avatar Apr 16 '15 06:04 mturnwall

You can probably just use CSS transform: translateY() to move them up. The class is .ct-label.

danieldiekmeier avatar Apr 17 '15 09:04 danieldiekmeier

This can be done using the draw events. Unfortunately we have a lack in documentation here. You can search the github issues for draw events https://github.com/gionkunz/chartist-js/search?q=draw+events&type=Issues&utf8=%E2%9C%93 for some examples.

gionkunz avatar Apr 19 '15 16:04 gionkunz

Its currently a bit hacky but we'll add more information to the draw events with #293

http://jsbin.com/wacuva/2/edit?css,js,output

Please discuss further if you need more help.

Cheers Gion

gionkunz avatar Apr 26 '15 14:04 gionkunz

@gionkunz thank you for the jsbin example. I am struggling with showing an actual bar value from data. Any help would be appreciated.

Based on your jsbin example I am trying to do something like that:

Example

Thank you.

ghost avatar Sep 30 '15 09:09 ghost

Just replace

    context.element.root().elem('text', {
      x: context.x1,
      y: context.y2 + 5
    }, 'ct-bar-label').text(seriesName);

with

    context.element.root().elem('text', {
      x: context.x1,
      y: context.y2 + 5
    }, 'ct-bar-label').text(context.value.y);

gionkunz avatar Sep 30 '15 12:09 gionkunz

@gionkunz thank you.

ghost avatar Oct 01 '15 08:10 ghost

@gionkunz is there a way to check if bar labels overflow each other and push them somehow?

screen shot 2015-10-07 at 12 46 27

As a potential solution set minimum bar height (regardless minimum value) which will make text:

a) always visible b) never overflown each other

ghost avatar Oct 07 '15 11:10 ghost

@ignaty did you ever figure out how to avoid the stacking labels? Thanks!

mdezc avatar Mar 23 '17 13:03 mdezc