-
-
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
IndexAxisValueFormatter behaves not as expected #1909
Comments
Also curious how IndexAxisValueFormatter is supposed to function. Currently half of my xAxis labels are not appearing even with |
I need @danielgindi to answer your Q1 In chart 2.x, due to the fact it's index based, so basically it's equal width. However in Chart 3.0, x axis is more like y axis, so you see your second pic, the x axis labels reflect the true distance to each other. However it seems weird again, 125 - 250 has longer distance then 500-1k, 1k-2k.. I am not sure why so right now. I think for your needs, you can just have x axis values to be 1,2,3,4,5 to make it equal distance, and then format it as your old 125,250,500,1k,2k? |
Hey @liuxuan30,
So if i´m getting it right, i already do what you propose. |
If x vals are already indexed numbers, I think it should be fine: If you then set the labelCount and enable forcelabelEnabled, it should be fine. What's your problem now? Can you print out the xAxis.entries to make sure it's [0,1,2,3,4,5]? Also, checking the formatter: open func stringForValue(_ value: Double,
axis: AxisBase?) -> String
{
let index = Int(value.rounded())
if index < 0 || index >= _valueCount || index != Int(value)
{
return ""
}
return _values[index]
} You also need to check |
My problem is My current solution works only because i disable the scrolling. But that´s a hack to me. And it´s not what the(my) user was used to. In Charts 2, the labels kept alignment to the data points even if i zoomed in. |
ok.. have you checked when you zoom, what are the xAxis.entries? |
@liuxuan30 |
Seems a bug to me now.. |
I don´t know enough about the inner functioning of Charts to make a guess here, sorry. |
found this in the source code // If granularity is enabled, then do not allow the interval to go below specified granularity.
// This is used to avoid repeated values when rounding values for display.
if axis.granularityEnabled
{
interval = interval < axis.granularity ? axis.granularity : interval
} If you set granularityEnabled to true you may prevent duplicate labels since your indices are fractions. Probably won't fix disappearing labels though, still trying to figure that out. |
I played a bit around with granularity. Set it to 0.1.. Enabled it.. Disabled it.. So far, nothing helped. |
As I said, |
I ended up with this exact same issue. The way I solved it was to set granularity to 1.0 for the xAxis. The issue was that we ended up with fractions on the x axis, thus grabbing the same entry twice and sometimes ending up with no entry. It's more obvious when you have very few entries so I forced it by having 2 values in a bar chart and this went haywire. Again, set the granularity of the axis you want an array with strings to 1.0 and it cleared it all up for me. |
Just want to share my experience, I solved this issue using a dynamic granularity, make chart adjust while zooming Important do not force labelCount First I have many datasets, so I group datasets values using
Adjust granularity base on how many columns you want to see Then set data Then I use a custom Formatter to calculate label to be shown
Set the custom formatter
Try and let me know. Happy coding! |
@samueleperricone Your solution works. I am able to zoom as well. Thank you |
It works.Thanks a lot.....i have added |
From the release notes of Charts 3.0.1:
I tried to use
IndexAxisValueFormatter
to achieve the same result as i had with Charts v2. But it behaves quite different.In Charts 2 i used
to achieve the following result:
The labels on the x-axis were always aligned to the value dots in the graph. Even when i zoomed in.
Now, to achieve the same with Charts 3.0.1 i tried
but the result was
As you can see, the labels appear ...somewhere. When you zoom, it sometimes fits. But mostly not.
My temporarily solution is to force the label count and lock scrolling, like this:
...because zooming would break it again. But this way it limits the user experience.
So my questions are:
IndexAxisValueFormatter
?The text was updated successfully, but these errors were encountered: