-
-
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
[Swift 3] LineChartData without xVals on constructor #1800
Comments
I was also struggling with this, but finally figured it out. You actually have to set it on the BarChartView itself using an axis value formatter: let labels = ["Value 1", "Value 2", "Value 3"]
barChartView.xAxis.valueFormatter = DefaultAxisValueFormatter(block: {(index, _) in
return labels[Int(index)]
}) It is definitely not as clean as the previous way of doing it. EDIT by danielgindiSince 3.0.1, you can also do: barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: labels) Also, you probably want to add: barChartView.xAxis.granularity = 1.0 |
@esalter-va Yeah! That really works!! But somehow the graphic is displaying more indexes than it should... It showing bizzare decimal numbers on "index" parameter like (3.5; 0; 0.69; 1.39; 2.09; 2.79; 3.5) and then it casts to Int (3; 1; 1; 2; 2; 3) but my yValues has only 4 items... Do you have this kind of problem? |
Nevermid! This problem was because the granularity! I tried granularity = 1 and works! |
@reicamargo Thanks for actually posting your solution, because I was having the exact same issue. All good now though! |
|
Hey guys. You can actually use the new So If you haven't set granularity - this will still behave correctly and not show labels for fractioned values. So this means that labels may be hidden when whole values are not rendered; |
How come when I do the whole xAxis thing, I get fatal error: PieChart has no XAxis: file? |
@danielgindi there is someone saying |
@danielgindi we should do that for every set? or it should be after we create the dataSet with all the sets?. Thanks |
I am sorry to post on closed issue. However, I have same problem, this solution is not working for me. |
I apologize for posting on a closed issue as well, but I have been reading up on this for the last 7 hours and am lost. Let's say you want to have an x-axis label for every day of the week. If you use the solution posted by esalter-va, the labels seem to be dependent on the backing data. That is, if you only have data for Monday, the index referenced by the value formatter will only ever be equal to the Int representation for Monday, and no other day. Thus, you will only get one label (Monday). If you want a label for each day no matter if you have data for that day, how do you do it? |
@bsachetta. You are not alone. I’ve been struggling with this problem for weeks. As far as I can tell, there is no support for a null data point. You must have a value for every sequential xAxis or you’ll have to figure out how to skip over them yourself. I was able to figure out how to do this and it kind of works but it falls apart when you don’t have enough data points to fill up the viewport. |
I know that "All dataset constructors have changed - they do not take an array of x-indices anymore" but how do I put strings on my x axis now if LineChartData doesn't have a "xVals" parameters anymore???
Before was so easy to do that...
The text was updated successfully, but these errors were encountered: