-
-
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
Pie Chart Legends Missing with the dynamically filled data. #518
Comments
Do you have the data code I can reproduce it in the ChartsDemo? |
Basically I am guessting the problem should be in Each time when you call pieChart.data = yourData, it will invoke public override func notifyDataSetChanged()
{
if (_dataNotSet)
{
return
}
calcMinMax()
if (_legend !== nil)
{
_legendRenderer.computeLegend(_data)
}
calculateOffsets()
setNeedsDisplay()
} I am not sure what's your exact procedure for 'static' and 'dynamic' way to set the data, you can try dynamicly add the value and see if each time the pie chart is redrawed and renderLegend is called and have your latest legends. You are welcome to debug it. |
Thank you for the response. What do you mean by the data code please let me know I will provide.I am using the latest release, I couldn't try the charts demo since it is in objective C and I work with swift only. |
OK, could you zip a sample project with the pie chart bug? |
Same problem for me. After filling the chart initially with data, every works fine (first screenshot). However, after clicking one of the segmented controls, which filters the data, the legend gets messed up. The interesting thing is that the values and the amount of categories displayed in the chart is correct. It's just not correct in the legend part. By the way: printing the values for legend and data values gives me correct results. Is there a way of resetting the legend I might be missing? Thanks for the support! |
Hi simon4ever, I tried to replicate it with the static data and it works fine for me, however whenever I use the dynamic code I get the same problem again and again. So I tried to debug it as much as i could and found that exact same code works fine when I generate the data in application and feed it to chart but when I get the data from parse I get this problem. Here is a Working Demo of the pie chart with static data. I will soon post the non working example too. |
I might be wrong but this sounds like an issue of doing UI operations not on the main thread. That would be what I would check first since you said t works fine when the app generates the data but not when it comes from parse. I'm assuming you are fetching the data from parse not on the main thread. |
That might be the case but can you please elaborate what you mean by not fetching the data on main thread. Here is what I am doing - 1 - Have a class datamodel in that model I am fetching data from parse asynchronously and on successful completion of fetch I am invoking a delegate method. You can check the code for this part in stack overflow here .Here is the data which I am printing just before setting the chart in real app-
Here is what I am doing in demo app -
You can check the second part here |
Okay, my approach is really similar to AppsWise's way:
Now, I assumed that both of these operations run in the same thread. But I may be wrong, because I am not an iOS expert for sure. |
Well when doing asynchronous work usually to set it to be done in the background so when it finishes you need to switch back to the main thread if you want to do actions on the UI. You want to do so since all UI actions HAVE to happen on the main thread. That is maybe why you are seeing some undefined behaviour. If this is the case you need to do something like this:
|
Hi Peterster, Thanks for putting thoughts around it, I tried dispatch_async(dispatch_get_mainqueue()) at various places, it doesn't seems to solve the problem here is what i tried.
Executing the whole set chart logic in main queue. But the result was same.
This also doesn't work. I also tried executing whole delegate method in main queue in data model as -
But this also did not work. Can you please help to find if i miss anything or doing something wrong here ? For a change to debug it more I will try to put bar chart or some other chart and see if that also miss the label or legends. Will update soon. |
I don't know. Looks correct. Could you create a sample project that does this and then send it to us so that we can check if it's a bug. Thanks. |
@petester42 @liuxuan30 User Name - Demo Thanks & Regards |
I've found the problem. You are doing operations on the chart after setting the data. This seems to cause issues. If I change the
Seems like not setting the colors on the dataset before the data will not show the legend properly. I don't know if this could be considered a bug. What do you think @danielgindi. |
Thanks, moving the part where the data is set to the end of my setPieChart function solved the issue! 👍 |
Wonderful works perfectly fine. Thank you very much to all of you. |
I have met some issues also related to the order; I always call setData after everything is settled down. Also wondering could this be improved. But we indeed needs to calculate some values that's related to the chart setting. |
In Swift 3
is not available, it giving error cannot invoke method. |
use Chart 3.0 APIs and refer ChartsDemo. |
While creating data entries for Pie Chart use
instead of
also change the array type to Doing this, you will get all the legends corresponding to every data. |
I am trying to implement pie chart from ios-charts library everything is working great, however the legends are missing from the graph. The dataPoints and values are supplied dynamically through a for loop
I have also logged this issue in SO Pie Chart Legends Missing
Request Help for same.
Thanks & Regards
The text was updated successfully, but these errors were encountered: