ChartsOrg / ChartsOrg/Charts

BarChart bottom legend issue

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

Fill barchart entries with simple dates (10-02-2021, 10-01-2021, 25-12-2020) and set an AxisFormatter to set the string value for the month.

## What did you expect to happen?

Set the bars with their month.

## What happened instead?

When the dates aren't ordered (e.g. feb-21, jan-21, dec-20, nov-20) the "stringForValue" function in the AxisFormatter doesn't recognize the correct month, instead set all the missing values for the months and repeats that method for at least 4 more times, sometimes 5 times.

## Charts Environment

**Xcode version: 12.5
**Swift version: 5.3
**Platform(s) running Charts: iOS 14.3

## Swift File that sets the barDataSet

let barEntries = (0.. BarChartDataEntry in
let dateIndex = data[i].date.index(data[i].date.startIndex, offsetBy: 10)
let strDate = String(data[i].date[.. String {
return getMonth(Int(value))
}

private func getMonth(_ month: Int) -> String {
switch month {
case 12:
return "Dic."
case 11:
return "Nov."
case 10:
return "Oct."
case 9:
return "Sept."
case 8:
return "Ago."
case 7:
return "Jul."
case 6:
return "Jun."
case 5:
return "May."
case 4:
return "Abr."
case 3:
return "Mar."
case 2:
return "Feb."
default:
return "Ene."
}
}

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the unordered dates and the shown BarChartDataEntry values, then inspect how AxisFormatter.stringForValue is called for the bar chart axis. Done means each bar receives the correct month label without repeated missing values or incorrect formatter results.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.