ChartsOrg / ChartsOrg/Charts

Stacked bar chart valueColors

Open
#945 3 comments 0 reactions 1 assignee Claimed by @jjatie View on GitHub
enhancement
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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))
```

```
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.