0

I'm using mpandroidchart to create a StackedBarChart. My stacks have a varied number of values - some have 8, some have 10. I'd like to be able to control the colour of each value based on its index in the stack. Furthermore, some have values that are 0, so it will look like they've got 1 less value.

eg 1st item in all stacks is red

2nd item is all stacks is blue etc.

This code doesn't work;

    BarDataSet mySet = new BarDataSet(MyList, "MyName");
    mySet.setColors(new int[]{R.color.stackbarchart_f0, R.color.stackbarchart_f1, R.color.stackbarchart_f2, R.color.stackbarchart_f3, R.color.stackbarchart_f4, R.color.stackbarchart_f5, R.color.stackbarchart_f6, R.color.stackbarchart_f7, R.color.stackbarchart_f8, R.color.stackbarchart_f9, R.color.stackbarchart_f10}, this);

It just loops through the colours, and seemingly ignore blocks with a value of 0. This means if a block has 8 values, the next stack will start with the 9th colour. I want that next stack to re-start at the 1st colour.

ausgeorge
  • 975
  • 1
  • 12
  • 23
  • check this https://stackoverflow.com/questions/46891073/how-to-set-different-colour-for-each-staked-value-of-stackedbarchart/47011630#47011630 – sauvik Feb 21 '18 at 05:44
  • Thanks amarok - I used the solution on that page and all blocks are the same colour. – ausgeorge Feb 21 '18 at 06:15

0 Answers0