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

Setting a pieChartDataSet on 3.0 #1681

Closed
giuseppe4 opened this issue Oct 19, 2016 · 3 comments
Closed

Setting a pieChartDataSet on 3.0 #1681

giuseppe4 opened this issue Oct 19, 2016 · 3 comments

Comments

@giuseppe4
Copy link

Hello,
I read issue #1474 about migration to 3.0 and other issues referred to it but I can't understand how to set data in PieChart on Swift 3.0 and Chart 3.0.

Could please anyone give me an example?

Thank you very much

@serefbulbul
Copy link

serefbulbul commented Oct 19, 2016

Hello,

This codes should work for you

var values: [PieChartDataEntry] = []

let dataEntry = PieChartDataEntry(value: 1.0, label: "Bla bla")         
values.append(dataEntry)

let pieChartDataSet = PieChartDataSet(values: values, label: "Bla bla")
pieChartDataSet.sliceSpace = 1
pieChartDataSet.colors = [UIColor.red, UIColor.yellow, UIColor.blue]

self.pieChart.data = PieChartData(dataSet: pieChartDataSet)

@giuseppe4
Copy link
Author

giuseppe4 commented Oct 19, 2016

Thank you very much! It works great! I didn't notice I was using
PieChartData(dataSets: pieChartDataSet)

Thank you!

@Farzana2014
Copy link

Farzana2014 commented Nov 29, 2016

Yes. Its work great. But i am facing problem to get the selected dataset index.
i have two entry

let dataEntry = PieChartDataEntry(value: 1.0, label: "Bla bla")
values.append(dataEntry)
        
let dataEntry2 = PieChartDataEntry(value: 2.0, label: "Bla")
values.append(dataEntry2)

I am using

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
        print(highlight.dataSetIndex)
 }

Always getting 0 as highlight.dataSetIndex value. Why? How i can get the right selected index?

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

3 participants