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

How can I draw bubble charts in swift project. #841

Closed
idrisyildiz7 opened this issue Mar 13, 2016 · 3 comments
Closed

How can I draw bubble charts in swift project. #841

idrisyildiz7 opened this issue Mar 13, 2016 · 3 comments

Comments

@idrisyildiz7
Copy link

I spend too much time but I could not find any documents and example for bubble charts.

@neel4r
Copy link

neel4r commented Mar 13, 2016

check the demo app code

@liuxuan30
Copy link
Member

@neel4r is right

@idrisyildiz7
Copy link
Author

There is ob-c code but I converted to swift. Thanks.

func setChartBubble(dataPoints: [String], values1: [Double],values2: [Double],values3: [Double],sortIndex:Int) {

    var dataEntries1: [BubbleChartDataEntry] = []
    var dataEntries2: [BubbleChartDataEntry] = []
    var dataEntries3: [BubbleChartDataEntry] = []


    for i in 0..<dataPoints.count {

        let dataEntry = BubbleChartDataEntry(xIndex: i, value: values1[i], size: CGFloat(values1[i])*10)
        dataEntries1.append(dataEntry)
    }


    for i in 0..<dataPoints.count {

        let dataEntry = BubbleChartDataEntry(xIndex: i, value: values2[i], size: CGFloat(values2[i])*10)
        dataEntries2.append(dataEntry)
    }


    for i in 0..<dataPoints.count {

        let dataEntry = BubbleChartDataEntry(xIndex: i, value: values3[i], size: CGFloat(values3[i])*10)
        dataEntries3.append(dataEntry)
    }

    let chartData1 = BubbleChartDataSet(yVals: dataEntries1,label: "label1" )

    let chartData2 = BubbleChartDataSet(yVals: dataEntries2,label: "label2")

    let chartData3 = BubbleChartDataSet(yVals: dataEntries3,label: "label3")

    chartData1.colors =  [UIColor(red: 33/255, green: 150/255, blue: 254/255, alpha: 1)]
    chartData2.colors =  [UIColor(red: 62/255, green: 89/255, blue: 254/255, alpha: 1)]
    chartData3.colors =  [UIColor(red: 255/255, green: 70/255, blue: 48/255, alpha: 1)]

    let dataSets: [BubbleChartDataSet] = [chartData1,chartData2,chartData3]

    let data = BubbleChartData(xVals: dataPoints, dataSets: dataSets)

    bubbleChartView.data = data;
    bubbleChartView.descriptionText = ""
    bubbleChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .EaseInBounce)

}

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