-
-
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
One implementation for grouped bar chart support in CombinedChartView #269
Conversation
@PhilJay maybe we can discuss about what you have in mind. |
Today I found a bug for my implementation for getDataSetByIndex in highlighter. It will search barData first and return its dataSetIndex, however, this index might not be the same on in combinedChartData. It depends on the order of setting lineData and barData. My implementation would prefer barData more than lineData. Gnenerally it works, but when comes to highlight the line dot and chart marker, it cannot get the correct dataSetIndex for line data. Update: I have fixed the issue I mentioned in commit No.2 |
I have fixed the issue I mentioned in commit No.2 |
@liuxuan30 I haven't had the time yet to look at the issue with grouped bars in combined charts... Did you have success with it? What's the status of this PR - does it correct it? |
Oops, I'm sorry that I just test it again, it has bug while trying to highlight each bar with commit 90a327d. The second commit is mainly for supporting the chart marker feature, I want it to support single bar and line data marker. It returns the index in combined chart data set rather than the index of bar data set in commit 90a327d, and it works for the chart marker but break the highlight logic. I'm lost here, because I want to know the dataSet type to know which transformer to use. Old logic just return a dataSetIndex in each sub chart data, so I changed it to return the index in combined chart data, so I can know the type. If we still use old logic, then I have to add a new parameter dataSetType for getMarkerPosition. Please advice. My project is different logic for highlighting, so I don't find this issue while pushing 90a327d, my bad. I have been using this implementation for a while, no big issues reported. Just some corner cases, and this chart marker problem. To me, I have to support grouped bars in combined chart, according to my Boss :( So it solves my problem, and most likely can help others, but I'm not sure if it's the best way to do so. I raise this PR is to discuss. If there are people had similar requests, they can try it out. I don't suggest you merge this, at least we need to think about many stuff, like highlighting, chart marker, etc. |
@danielgindi I am occupied with some dev work recently, I will update as soon as I got some time. |
I have to delay the merge with master again.. I need feedback about if the idea is good to go, before we could talk about it I would reduce the freq to solve conflicts, too much work on my plate.. |
@liuxuan30 can you separate out the PR 1bd8c22 ? It does not have any dependencies on any other changes and is being blocked by the wider PR issues in this thread. |
@jwardle wow You even find this change inside a PR. I will take a look at the current code and may file one later |
@danielgindi Can you get this notification? I am having sometime to resolve the conflict. But I stucked at the data provider. My solution will need to fedd two different transformers for bar chart renderer and other charts. However I cannot simply override the getTransformer method to get it done. Now my way is to modify the barChartDataProvider like this: So I can provide the correct value for the bar chart. Any better ideas? The old renderer delegate works because each chart renderer has its own protocol, so I can provide everything they needs. Is it possible in swift that the combined chart view's getTransformer method could know which renderer is asking for transformer? |
Well I think that the transformer at this point is the same inside a
combined chart,
but you're having problems with this you can add more functions to the
protocol...
|
Is it possible in swift that the combined chart view's getTransformer method could know which renderer is asking for transformer? |
I could think of some options, but that wouldn't be right if custom But I think that the providers should have their function naming more like בתאריך יום שישי, 30 באוקטובר 2015, Xuan [email protected] כתב:
|
Alright, I will use barChartXMin, barChartXMax, etc for the bar chart data provider. Last issue is the highlight - need to figure out a way to highlight the bar, the line dot or the bubble. |
1bd8c22
to
39b116f
Compare
@danielgindi I got a whole day on this and get it work with some flaws. The biggest change is, I will return the dataSetIndex of combinedChartView.data, not each sub data's. Because line data set can have 0 index, and bar data set could also have one. So it's not unique to identify which dataSet should be used. Using the data set index of combined data gives me a chance to know which dataSet and chart type it is. I also rewrite the highlight logic for combined chart view, just to a math to get the data set index of the sub data and call the specific renderer to draw it. The problem is about the highlight. I had a hard time to figure out a way, and still no good one yet. I think there are two things we need to confirm:
|
39b116f
to
6fa4b7c
Compare
@danielgindi what's the reason for closing? I know it has been an old PR... But we never discussed about this feature formally. |
It's because it's not a final solution- you said you have more work on it but hadn't had the time yet. Feel free to re-open if there's any news :) |
@danielgindi I think my work is almost done except for those conflicts; I updated once after the chart data provider is introduced. For the current conflicts, it should not be hard to resolve; |
Yes we need to carefully investigate this. I need to find the time for this :-) |
8752575
to
453c0c0
Compare
…the whole data, not each sub data's index add one more bar data set in demo view controller (+4 squashed commits) Squashed commits: [44ce60e] rename some BarChartDataProvider protocol methods not the same as ChartDataProvider [1bd8c22] Fix issue ChartsOrg#329 check _deltaX when only lineData exists [90a327d] 1. fix bug in getDataSetIndex, it will detect what dataSet it is and determine how to proceed 2. I also override getMarkerPosition for CombinedChartView [80aa1b3] add support for grouped bars in CombinedChartView. add a new demo view controller called GroupedCombinedChartViewController, to illustrate multiple bars + multiple line
453c0c0
to
d5b866f
Compare
synced with master today :) Be aware I had implemented a grouped bar combined view controller in ChartsDemo, to get familiar with my implementation. |
Man I think that this is not required now - with the new way of calculating bar groups. Thanks for all your efforts on this matter!!! |
🎆 happy birthday to this PR one week later and finally closed :D |
:) |
Here's link to wiki that describes the official implementation: https://github.com/PhilJay/MPAndroidChart/wiki/Setting-Data#grouped-barchart Example code in this PR is misleading, as it never got merged in. |
Why you mention this closed PR then. It's my implementation while grouped bars are not supported in Chart v2. However, v3 already supported it. |
@liuxuan30 I was just Googling around this problem, and this issue is the prominent result, so I thought I'd leave some pointers for the next guy. |
Chart v3 already support grouped bars. Just check out charts demo |
I got one implementation for grouped bar chart support in CombinedChartView today to address issue #252
I add a new demo view controller called GroupedCombinedChartViewController, to illustrate multiple bars + multiple lines
I have no intention to merge this PR, as you must have many suggestions and questions :-)
I want to start a discussion about the implementations, and perhaps we can find a good one.
My idea is to add a few properties as the bar chart renderer and transformers, and use bars transformers to locate the xIndex and dataSet to highlight. Other like line/bubble, just use the xIndex and dataSet to highlight their data points.
Pros:
Straightforward, easy to understand and implement
Cons:
I have to create a CombinedChartHighlighter and copy the code from BarChartHighlighter, as I cannot create _highlighters (like CombinedChartRenderer does) nor I can subclass BarChartHighlighter, but I did need the code to calcuate bar stuff.