ChartsOrg / ChartsOrg/Charts

leftAxis custom entries

Open
#3,786 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Chart: LinesChart

I am trying to replace leftAxis calculated entries by custom ones, in order to get custom visible values on the axis.
In leftAxis I have axisMinimum = 0 and axisMaximum = 100.
I would like to have displayed only certain values (13, 46, 87, 98), but can't achieve it with granularity label count or IAxisValueFormatter -> stringForValue.

I am trying
```
leftAxis.entries = [ 13.0, 46.0, 87.0, 98.0]
updateChartData()
```
However, it internally overrides it, and I still have entries = [10, 20...100]

I get a solution overriding entries in **YAxis.swift** file with a custom _setAxisLabelPositions(positions: [Double])_ function as follows, but I would like to solve it using library capabilities instead:

```
@objc private var _entries = [Double]()

@objc private var forcedEntries: [Double]?

@objc open func setAxisLabelPositions(positions: [Double]) {
forcedEntries = positions
}

@objc override open var entries: [Double] {
get
{
return forcedEntries ?? _entries
}
set
{
_entries = newValue
}
}

```
Other solution could be turning leftAxis initializer open in BarLineChartViewBase.swift, so we could implement custom axis behavior:
` @objc open var leftAxis = YAxis(position: .left)`

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.