You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My suggestion:I think Whether to round a number should be decided by user, because some number is more significant before rounding, for example a UNIX timestamp in this issue---UNIX timestamp is intended to be formatted to a date string generally. Maybe we can add a property to let user to decide whether to round a number that is showed on xAxis.
Update again(Issue solved):
I have handle this problem by modifying a few lines code in Charts' source code in AxisRendererBase.swift...
change:var interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval)) to var interval = Double(rawInterval)
2.comment out these codes:
// Normalize interval
let intervalMagnitude = ChartUtils.roundToNextSignificant(number: pow(10.0, Double(Int(log10(interval)))))
let intervalSigDigit = Int(interval / intervalMagnitude)
if intervalSigDigit > 5
{
// Use one order of magnitude higher, to avoid intervals like 0.9 or 90
interval = floor(10.0 * Double(intervalMagnitude))
}
update(supplement):
the value(UNIX timestamp) that I got from stringForValue:axis: protocol function are all convert last five number to zero, this may cause obvious problem.
(lldb) po value
1473900000
(lldb) po value
1474000000
(lldb) po value
1474100000
My xAxis is set to show date by day:
xAxis.granularity = 60.0 * 60 * 24;
I implement my own date formatter with IChartAxisValueFormatter protocol, however, the protocol function
pass on a value that was not what I have set in ChartDataEntry's init function:
[[ChartDataEntry alloc] initWithX:xValue y:];
value is not equal to xValue, for example, I set x's value to 1473782400, but the value what I got from stringForValue:axis: protocol function is 147380000 , so it lead the chart render vertical grid and x's label at unexpected place:
The text was updated successfully, but these errors were encountered:
Huang-Libo
changed the title
(v3.0 + Swift3.0)IChartAxisValueFormatter protocol
(v3.0 + Swift3.0)IChartAxisValueFormatter's protocol function pass on a unexpected value
Sep 21, 2016
Huang-Libo
changed the title
(v3.0 + Swift3.0)IChartAxisValueFormatter's protocol function pass on a unexpected value
(v3.0 + Swift3.0)IChartAxisValueFormatter's protocol function pass on a unexpected value(double value discard)
Sep 21, 2016
The label that is showing - is showing the correct value for the x-value it points at.
So the short answer is - what you might actually need is to use the granularity feature.
The longer answer is:
The axis calculations are there for a reason. And there's no difference what kind of value you pass in - they are all on an axis, and you should be able to represent any point on the axis with your kind of value.
However, some times you want to control how small the steps between axis labels (or grid lines) can be. That's what granularity is there for.
Also a note: In Cocoa/CocoaTouch, NSTimeInterval is a more appropriate value to represent dates, and actually represents seconds. It is much more intuitive to work with, especially when tackling such problems. You can see the time chart demo.
My suggestion:I think Whether to round a number should be decided by user, because some number is more significant before rounding, for example a UNIX timestamp in this issue---UNIX timestamp is intended to be formatted to a date string generally. Maybe we can add a property to let user to decide whether to round a number that is showed on xAxis.
Update again(Issue solved):
I have handle this problem by modifying a few lines code in Charts' source code in AxisRendererBase.swift...
var interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval))
tovar interval = Double(rawInterval)
2.comment out these codes:
update(supplement):
the value(UNIX timestamp) that I got from
stringForValue:axis:
protocol function are all convert last five number to zero, this may cause obvious problem.(lldb) po value
1473900000
(lldb) po value
1474000000
(lldb) po value
1474100000
My xAxis is set to show date by day:
I implement my own date formatter with
IChartAxisValueFormatter
protocol, however, the protocol function-(NSString *)stringForValue:(double)value axis:(ChartAxisBase *)axis
pass on a value that was not what I have set in ChartDataEntry's init function:
[[ChartDataEntry alloc] initWithX:xValue y:];
value is not equal to xValue, for example, I set x's value to 1473782400, but the value what I got from
![unix timestamp issue](https://cloud.githubusercontent.com/assets/12227130/18696429/997fb4ca-7feb-11e6-9455-38461056bdb5.png)
stringForValue:axis:
protocol function is 147380000 , so it lead the chart render vertical grid and x's label at unexpected place:The text was updated successfully, but these errors were encountered: