ChartsOrg / ChartsOrg/Charts

Legend position above yAxis bar chart

Open
#2,649 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

How can I set properly legend position right above yAxis (so it will look like attached image1 always)
![1](https://user-images.githubusercontent.com/8360470/28716242-c2f965fa-73a4-11e7-9544-c1f764dcedef.png)
Now I did like this:
let legend = barChart.legend
legend.form = .none
legend.textColor = UIColor.white
legend.verticalAlignment = .top
legend.horizontalAlignment = .left
legend.direction = .leftToRight
legend.xOffset = -160.0 (bad hardcode)
leftAxis.spaceTop = 0.16 (some space for legend)

so sometimes yAxis values almost covered my legend (image 2):
![3](https://user-images.githubusercontent.com/8360470/28716241-c2d57618-73a4-11e7-941c-c6e4779da273.png)
or in other way - too far (image 3)
![2](https://user-images.githubusercontent.com/8360470/28716240-c2d51434-73a4-11e7-818e-1539b198531e.png)

maybe I should use not legend, but some other instrument from bar charts?

Thank you in advance for answer

Contributor guide

Open the contributing guide

Research direction

Start with the barChart.legend and leftAxis configuration described in the issue, reproducing the three shown positioning outcomes across different chart sizes and y-axis values. The work is done when the legend remains directly above the yAxis without relying on the hardcoded xOffset or manually reserved spaceTop.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data-visualization, mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.