ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.59k stars 6k forks source link

Stacked bar chart valueColors #945

Open dxclancy opened 8 years ago

dxclancy commented 8 years ago

Hi, I'm not sure the intent of Charts, so I'm not sure if this is a bug or just an implementation detail.

Say you have a stacked bar chart with 3 values per bar, and want to control the text color of the value within each part.

BarChartDataSet dataSet; 
(...)
dataSet.colors = @[[UIColor yellowColor], [UIColor purpleColor], [UIColor darkRedColor]];
// chosen to contrast with above, as black will be hard to read on purple and darkRed
dataSet.valueColors = @[[UIColor blackColor], [UIColor whiteColor], [UIColor whiteColor]];

In the current implementation you end up with the 1st bar drawing black text over yellow, purple, and darkRed, and the 2nd bar drawing white over yellow, purple, and darkRed.

What I would like is to have those colors rotated per bar part. So that black text is drawn over yellow, white over purple, white over darkRed.

For bar charts, this seems more logical to me then the colors applying to the entire bar, but I'm sure I haven't considered all the cases, or perhaps I am missing some other configuration that accomplishes this.

The behavior that I describe as desired above can be accomplished in HorizontalBarChartRenderer by changing this:

                                drawValue(context: context,
                                    value: valueText,
                                    xPos: x,
                                    yPos: y + yOffset,
                                    font: valueFont,
                                    align: textAlign,
                                    color: dataSet.valueTextColorAt(j))
to this:
                                color: dataSet.valueTextColorAt(k))
liuxuan30 commented 8 years ago

I see your point. you want to label has different color for each segment, and each bar has the same pattern. Currently the same bar will have the same text color, not the segment. Currently you can change to k on your side. We need time on this.

However, people may want what the current is. Seems we could add more switches? @danielgindi what you think?

danielgindi commented 8 years ago

I'm not sure. @PhilJay ? :8ball:

dxclancy commented 6 years ago

Curious why this was closed? Issue has not been addressed.