Skip to content
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 how to get the index of the selected slice.??? #1267

Closed
parth4054 opened this issue Jul 24, 2016 · 14 comments
Closed

PIE-CHART how to get the index of the selected slice.??? #1267

parth4054 opened this issue Jul 24, 2016 · 14 comments

Comments

@parth4054
Copy link

i have looked at almost the whole library . but i could not find how do we get the index of the slice selected . please help me with this . i am stuck at this from a weak . please help.

@liuxuan30
Copy link
Member

did you checked the delegate protocol? It seems like chartValueSelected() is enough, the index should reside in entry or highlight

@parth4054
Copy link
Author

Hi , thanx for the quick reply . I could not find the delegate protocol in the library .(swift library)
And also i am a bit new to ios . Could you please guide me a little on how to achieve this exactly. ?
Thanx in advance

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 25, 2016

Just search chartValueSelected, and play with ChartsDemo. And learn something about protocol then you are good to go.

@parth4054
Copy link
Author

sir , i have searched chartValueSelected everywhere in all swift classes. i am not able to find it.
i know that chartsValueSelected is in charts demo which is made up of objective c files.
But i am using the swift library .

@parth4054
Copy link
Author

sir , i found it finally . thank you very much for the awesome library and your quick and helpful reply. have a nice day . cheers !

@parth4054
Copy link
Author

sir , just one last question.
i have implemented the delegate protocol in my class and used the delegate function i.e chartValueSelected. but it is not getting called when i click the pie chart slice.
please answer this last question. thanx a lot :)

@liuxuan30
Copy link
Member

I would you suggest to take a look at ChartsDemo, there are examples

@parth4054
Copy link
Author

sir , i am sorry for disturbing you again and again but i am frustated. my delegate function is not getting called. please help me.
this is the function : optional func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: ChartHighlight)

i have tried setting the delegate in my class and have searched hundreds of questions on stackoverflow but not able to get anywhere.

please let me know the exact steps to follow to make this work.

please help sir. i really need it

@parth4054
Copy link
Author

parth4054 commented Jul 26, 2016

let me tell you what i have done.
I BEG YOU PLEASE SEE THIS AND HELP ME :(

class Test : UIViewController {

viewDidLoad(){

setChart()
}

func setChart(){

var obj = Test()
obj.delegate = self

}

}

extension Test : ChartViewDelegate {

func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: ChartHighlight) {

print(chartDataEntry)
}

}

i have done it this way and i know something is wrong here. please tell me what to do exactly.

I BEG YOU! :(

@dxclancy
Copy link

Hi, I'm not a chart collaborators but I use charts.

For your specific case above, you are declaring an object of Test and trying to use it's delegate to get selected notifications, but Test is a UIViewController and is not descending from any ChartView, so it's delegate cannot be a ChartView delegate.

This is basic iOS programming that you will learn more effectively elsewhere.

There is a technique that you can, and indeed should, use when writing your own chart, or debugging one. You should always start from and/or refer to the demo.

When starting a new chart, find the corresponding code in the demo, copy it to your class, and run and verify that it works just like it does in the demo. Check this version into source control.

Now that you know you have a working version, you can begin modifying it. In this way you will know that any changes you make are your own issue, and you can go back to when it worked.

In your specific case, go to ChartsDemo and look at PieChartViewController. Set a breakpoint in chartValueSelected. Then run it in the iOS simulator, and chose Pie Chart from the list. Click on a pie piece, and you will see that your break point is hit. This means that it is likely the issue you are having is not a charts issue. You can use this file as a starting point.

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 27, 2016

Thanks @dxclancy
@parthandroid I'm sorry to let you down, but seems you are just starting programming, I suggest take your time to find some tutorials and search on stack overflow.

At least you should be write below on your own:

let pieChart = PieChartView()
pieChart.delegate = self

and implement ChartViewDelegate protocol in your view controller

@parth4054
Copy link
Author

thanx alot . i am just new to delegates not a beginner in programming

@parth4054
Copy link
Author

dxclancy. thanx brother for getting straight to the point and explaining me the concept.
so nice of you :)

@janeshsutharios
Copy link

@liuxuan30 I just added manually marker using chartView.highlightValue(x:1,y1,dataSetIndex:1) I just want to know that from where can i get dataSetIndex ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants