Charts: PIE-CHART how to get the index of the selected slice.???

Created on 24 Jul 2016  路  14Comments  路  Source: danielgindi/Charts

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.

All 14 comments

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

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

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

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 .

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

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 :)

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

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

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! :(

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.

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

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

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

@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 ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

newbiebie picture newbiebie  路  3Comments

BrandonShega picture BrandonShega  路  4Comments

brytnvmg picture brytnvmg  路  4Comments

sjdevlin picture sjdevlin  路  3Comments

Shunshine07 picture Shunshine07  路  3Comments