-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOLVED: Round number less than zero x values issue #1916
Comments
I have this problem too. |
I tried in ChartsDemo bar chart: leftAxisFormatter.negativeSuffix = @" $";
leftAxisFormatter.positiveSuffix = @" $";
leftAxisFormatter.minimumIntegerDigits = 1;
ChartYAxis *leftAxis = _chartView.leftAxis;
leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
leftAxis.labelCount = 8;
leftAxis.valueFormatter = [[ChartDefaultAxisValueFormatter alloc] initWithFormatter:leftAxisFormatter];
It works fine. open var valueFormatter: IAxisValueFormatter?
{
get
{
if _axisValueFormatter == nil ||
(_axisValueFormatter is DefaultAxisValueFormatter &&
(_axisValueFormatter as! DefaultAxisValueFormatter).hasAutoDecimals &&
(_axisValueFormatter as! DefaultAxisValueFormatter).decimals != decimals)
{
_axisValueFormatter = DefaultAxisValueFormatter(decimals: decimals)
}
return _axisValueFormatter
}
set
{
_axisValueFormatter = newValue ?? DefaultAxisValueFormatter(decimals: decimals)
}
} |
I'm sorry but I said I'm writing in Swift but you replied with the objective-c example. I think you haven't even read my code but, I don't know why, you closed the topic without giving an acceptable answer. |
I read the code, run tests and debug with ChartsDemo, saying it's fine and needs you to debug on your side to know why the formatter is replaced or changed so |
I'm sorry if I was a little hard with you, but I'm learning coding by my self, I opened a thread because I can't find a solution to my problem and you close the thread without giving me actually a real solution. And if you close immediately the thread I get much less chances to be reached by other people (I have no doubt that Charts API works well). Anyway I found this holy solution, now I write it down. |
It's fine. I close the issues because we need to keep it clean knowing what are the true issues and what are questions. |
I tried several methods and formatter to properly print x values with numbers smaller than zero. I can't print the "zero" digit before the dot, e.g:
Number ->Printed number
The issue is present both with not perfectly rounder numbers (eg. 0.3452) and with perfectly rounder numbers (eg 0.8)
The code above doesn't work and also experiments with
granularity
did not work.Swift/Charts 3.0.1
Found a solution with this tutorial
EDIT: Create an extension of the ChartViewController
Inside the class of ChartViewController declare a variable of type
IAxisValueFormatter?
and insideviewDidLoad()
set this new variable equal toself
Finally use
lineChartView.xAxis.valueFormatter = axisFormatDelegate
to set the proper formatter.The text was updated successfully, but these errors were encountered: