Skip to content

Conversation

@davidsansome
Copy link

Previously a DataSet's valueFormatter would be replaced with the default if it was any instance of the DefaultValueFormatter class, even one that had been customised.

This PR changes the valueFormatter to be optional, and will set it to the default when it's added to a chart only if it hasn't already been set by the user.

This fixes the formatting in some of the demo app charts too:

  1. The Positive/negative demo tries to set maximumFractionDigits to 1: before, after
  2. The Pie Chart demo tries to set a percent suffix: before, after

Fixes #4595, fixes #4599, fixes #4690, fixes #4802.

@chenn2013
Copy link

chenn2013 commented Oct 17, 2022

First set data, then set ValueFormatter,
In this order, we can solve the current problem

or edit the Source code DefaultValueFormatter.swift

open func stringForValue(_ value: Double,
entry: ChartDataEntry,
dataSetIndex: Int,
viewPortHandler: ViewPortHandler?) -> String
{
if let block = block {
return block(value, entry, dataSetIndex, viewPortHandler)
} else {
//TODO: Initialize the formatter you need here
return formatter?.string(from: NSNumber(floatLiteral: value)) ?? "";
}
}

@pmairoldi pmairoldi self-assigned this Mar 11, 2023
@pmairoldi pmairoldi added this to the 5.0.0 milestone Mar 11, 2023
@pmairoldi pmairoldi modified the milestones: 5.0.0, Future Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Percentage is not show on pie chart DefaultValueFormatter is not working on v4.0.1 Percentage Data Problem DataSet valueFormatter does not work.

3 participants