ChartsOrg / ChartsOrg/Charts

Xaxis value formatter not always correct

Open
#4,462 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

* [X ] I've read, understood, and done my best to follow the [*CONTRIBUTING guidelines](https://github.com/jjatie/Charts/blob/master/CONTRIBUTING.md).

## What did you do?

Created value formatter using the IAxisValueFormatter delegate. I wanted to replace the labels on xAxis with the month name I stored in an array. Tried to get the month name using the following code:
`func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return monthName[Int(value) - 1]
}`
I used the minus one because the value is the current month index, for example 9 for September which is index 8 in the array.

## What did you expect to happen?

The xAxis value should be replaced with the month name from the array

## What happened instead?

The value was replaced, but the index is not correct, for example sometimes there is an offset by 2, so instead of September November is displayed. But other times the offset is different, Month May was replaced with June, so only an offset of one.

## Charts Environment

**Charts version/Branch/Commit Number: 3.5.0/Master/14da743 **
**Xcode version:12 beta 6**
**Swift version: 5**
**Platform(s) running Charts: iOS**
**macOS version running Xcode: 10.15.6**

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.