chartist icon indicating copy to clipboard operation
chartist copied to clipboard

Colours of Bars in Bar graphs

Open meghaklp opened this issue 11 years ago • 10 comments

Hi, I am experimenting with chartist and I had few questions:

  1. Is there an easy way to make a stacked horizontal bar chart?
  2. Can bar charts have tool tips?
  3. Can each bar in a single series bar chart have a different colour (hypothetically)
  4. How can I over-ride the default colour of a single series bar chart? How do I specify it in the options.

Any help? Maybe these are not issues but, just questions. Thanks.

meghaklp avatar Mar 10 '15 13:03 meghaklp

  1. yes. check http://gionkunz.github.io/chartist-js/examples.html#stacked-bar-chart
  2. They can. However, tooltips should be developed on top of chartist. You can get an example of how to write tool tips in this article http://www.smashingmagazine.com/2014/12/16/chartist-js-open-source-library-responsive-charts/ . There is also an open issue for creating a tool tip plugin which I'm supporting (but have no time atm) #219
  3. Currently this is not possible but there is an open issue that tracks this: #209
  4. You can get an example for this here: http://jsbin.com/kowida/2/edit?html,css,js,output

gionkunz avatar Mar 12 '15 10:03 gionkunz

Thanks, this is very useful

meghaklp avatar Mar 18 '15 07:03 meghaklp

This is old but if other people came to it i just used CSS to color each bar and make repeating patterns. For example, if you had 4 colors you wanted to repeat you could use CSS like:

.ct-chart .ct-bar:nth-of-type(4n+1) {
  stroke: #71A28A;
}

.ct-chart .ct-bar:nth-of-type(4n+2) {
  stroke: #FF6414;
}

.ct-chart .ct-bar:nth-of-type(4n+3) {
  stroke: #EFB200;
}

.ct-chart .ct-bar:nth-of-type(4n+4) {
  stroke: #91A453;
}

OscarGodson avatar Oct 27 '15 22:10 OscarGodson

@gionkunz I am trying to have different colour for every bar. I have tried JSbin example you have mentioned here - http://jsbin.com/kowida/2/edit?html,css,js,output

For some reason CSS selector for every bar isn't working. I am using angular-chartist.js wrapper.

rajkaran avatar Dec 22 '15 17:12 rajkaran

Hi, How I can set different color to Bar in graph if its values are negative?

MishaBeskin avatar Mar 10 '16 14:03 MishaBeskin

Hi, How I can set different color to Bar in graph if its values are negative?

+1 This is something I could really use!

FelixBLimetta avatar Apr 07 '16 12:04 FelixBLimetta

Hi guys, check the advanced section on colour in the getting started documentation.

gionkunz avatar Apr 07 '16 13:04 gionkunz

@rajkaran I cannot get the CSS selectors to work on my page either. Did you ever figure out how to make each bar a different color?

purplelady105 avatar Jun 01 '17 22:06 purplelady105

@purplelady105 No I have not.. Moved onto other library.

rajkaran avatar Jun 02 '17 15:06 rajkaran

Colors for a single series bars:

.ct-bar{
	stroke-width: 40px;
}

.ct-bar:nth-child(1){
	stroke: #379683 !important;
}

.ct-bar:nth-child(2){
	stroke: #91A453 !important;
}

.ct-bar:nth-child(3){
	stroke: #EFB200 !important;
}

lubosdz avatar May 20 '20 15:05 lubosdz