ChartsOrg / ChartsOrg/Charts

PiChartView center label text scale

Open
#4,691 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

## What did you do?

I created a PichartView and passed text to the center label.

```
private lazy var pieChartView: PieChartView = {
let pieChartView = PieChartView()
pieChartView.shouldHideToolbarPlaceholder = true
pieChartView.legend.enabled = false
pieChartView.holeRadiusPercent = 0.83
pieChartView.noDataText = ""
pieChartView.highlightPerTapEnabled = false
return pieChartView
}()

```
```
private func setChartCenterText(_ response: InvoiceInfos) {
let amountAtt = NSMutableParagraphStyle()
amountAtt.alignment = .center
let amountWithComma = "\(response.amount)".replaceComma
let amountAttributetText = NSMutableAttributedString(
string: "\(amountWithComma) ₺",
attributes: [
.font: UIFont.medium18,
.paragraphStyle: amountAtt
]
)

let subAtribute = NSMutableParagraphStyle()
subAtribute.alignment = .center
let subAttributedText = NSAttributedString(
string: "\n\(response.energyExpended)".replacingOccurrences(of: ".", with: ",").replaceComma + " kWh", attributes: [
.paragraphStyle: subAtribute,
.font: UIFont.light14
]
)
amountAttributetText.append(subAttributedText)
pieChartView.centerAttributedText = amountAttributetText
}

```

## What did you expect to happen?

![Screen Shot 2021-07-26 at 15 07 10](https://user-images.githubusercontent.com/13396852/126986124-56141bf9-1afb-4649-9278-ba2e4b0178bb.png)

When a short value comes in it looks like I want it.

## What happened instead?

![Screen Shot 2021-07-26 at 14 46 18](https://user-images.githubusercontent.com/13396852/126984128-cef83514-00fc-406d-9c3b-cc55044239aa.png)

But I can't scale the long incoming text.
How can I scale PiChartView center label text?

## Charts Environment

Charts version: 3.6.0
Xcode version: 12.5
Swift version: 5.3
Platform(s) running Charts: iOS Platfrom

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with PieChartView and the provided centerAttributedText, comparing short and long values. Trace how the center label is laid out and identify the relevant tests or entry point; done means long center text scales or fits correctly while preserving the supplied formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.