ChartsOrg / ChartsOrg/Charts

IndexAxisValueFormatter behaves not as expected

Open
#1,909 17 comments 0 reactions 0 assignees View on GitHub
★★ bug
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

From the [release notes of Charts 3.0.1](https://github.com/danielgindi/Charts/releases/tag/v3.0.1):
> Added a new IndexAxisValueFormatter that you can pass an array of labels and have them behave like in Charts 2.0

I tried to use `IndexAxisValueFormatter` to achieve the same result as i had with Charts v2. But it behaves quite different.

In Charts 2 i used
```
LineChartData(xVals: ["125", "250", "500", "1k", "2k", "4k"], dataSets: dataSets)
```
to achieve the following result:

The labels on the x-axis were always aligned to the value dots in the graph. Even when i zoomed in.

Now, to achieve the same with Charts 3.0.1 i tried
```
chart.xAxis.valueFormatter = IndexAxisValueFormatter(values: ["125", "250", "500", "1k", "2k", "4k"])
```
but the result was

As you can see, the labels appear ...somewhere. When you zoom, it sometimes fits. But mostly not.

My **temporarily** solution is to force the label count and lock scrolling, like this:
```
let labels = ["125", "250", "500", "1k", "2k", "4k"]
chart.xAxis.valueFormatter = IndexAxisValueFormatter(values: labels)
chart.xAxis.setLabelCount(labels.count, force: true)
chart.scaleXEnabled = false
```
...because zooming would break it again. But this way it limits the user experience.

So my questions are:
1. Is this the expected behavior of `IndexAxisValueFormatter`?
2. What is the "best practice" way to achieve a result as in Charts 2?
3. If there is no way currently: Is it planned to support this behavior some day in Charts 3?

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.