Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coloring by bars and not by stacks in a StackBar chart #925

Closed
A1exandre opened this issue Apr 7, 2016 · 3 comments
Closed

Coloring by bars and not by stacks in a StackBar chart #925

A1exandre opened this issue Apr 7, 2016 · 3 comments

Comments

@A1exandre
Copy link

Hi all, and thanks @danielgindi & @PhilJay for this great piece of work :)

I have a chart with stack bars and I'm trying to have each bar with a different color.

However, when we have stack bars the barChartDataSet.colors property does not set the colors for the bars anymore but for the stacks.

Is there anyway to set the colors independently for each bar?
Thanks!

@PhilJay
Copy link
Collaborator

PhilJay commented Apr 7, 2016

dataSet.setColors(...)

dataSet.colors = ...

Just like you normally set colors. In stacked-bars, colors are reused for bars.

@PhilJay PhilJay closed this as completed Apr 7, 2016
@A1exandre
Copy link
Author

Sorry I wasn't very clear.
I use dataSet.colors = ...

However, it seems that the coloring automatically switch from coloring-by-bar to coloring-by-stack when we use stacks.

Because of this, i get that
screen shot 2016-04-07 at 10 24 59

And what I want is this
screen shot 2016-04-07 at 10 24 06
(My stacks are not supposed to have different colors, they should just be seen because of the borders)

I found a temporary fix by modifying the drawDataSet function of BarChartRenderer.swift.
Line 237 was CGContextSetFillColorWithColor(context, dataSet.colorAt(k).CGColor) and I replaced it with
CGContextSetFillColorWithColor(context, dataSet.colorAt(j).CGColor)

However, having a dataSet.colorByBar or dataSet.colorByStack property to do this would be nice.

@A1exandre A1exandre changed the title Coloring bars and not stacks in a StackBar chart Coloring by bars and not by stacks in a StackBar chart Apr 7, 2016
@liuxuan30
Copy link
Member

your cae is different, stack bar chart will repeat the value, but you don't want it. Then you have to customized it your self.
BTW, to me, it does not make sense(?) that a stacked bar chart should have the same color, unless you have other ways to distinguish them. However, from your screenshot, it looks just like a normal bar chart. Why using stack not normal for this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants