Git Product home page Git Product logo

Comments (4)

ridvank avatar ridvank commented on June 18, 2024

I will be looking for it today and let you know 👍

from rkpiechart.

RodrigoLara avatar RodrigoLara commented on June 18, 2024

I had the same problem, you just need to add a condition in the RKPieChartView class in the function calculateAngles(), "if item.endAngle! > 2 * π && items.count! = 1" , I leave the complete code of the function.

 private func calculateAngles()  {

    totalRatio = items.map({ $0.ratio }).reduce(0, { $0 + $1 })

    for (index, item) in items.enumerated() {
        item.startAngle = index == 0 ? 3 * π / 2 : items[index - 1].endAngle

        if items.count == 1 {
            totalRatio = 100
        }

        item.endAngle = item.startAngle! + (360 * item.ratio / totalRatio).degreesToRadians

        if item.endAngle! > 2 * π && items.count != 1 {
            item.endAngle = item.endAngle! - 2 * π
        }
    }
}

I hope help you

from rkpiechart.

soleilpqd avatar soleilpqd commented on June 18, 2024

My way, not sure about this:

    private func calculateAngles() {
        totalRatio = items.map({ $0.ratio }).reduce(0, { $0 + $1 })
        for (index, item) in items.enumerated() {
            item.startAngle = index == 0 ? 3 * π / 2 : items[index - 1].endAngle
            if items.count == 1 {
                totalRatio = 100
            }
            var diff = (360 * item.ratio / totalRatio).degreesToRadians
            let pi2 = π * 2
            while diff > pi2 {
                diff -= pi2
            }
            item.endAngle = item.startAngle! + diff
        }
    }

from rkpiechart.

usinuniverse avatar usinuniverse commented on June 18, 2024

If you have only one item, and you want It's occupy whole graph (100%), like this:

private func calculateAngles() {
        totalRatio = items.map({ $0.ratio }).reduce(0, { $0 + $1 })
        for (index, item) in items.enumerated() {
            item.startAngle = index == 0 ? 3 * π / 2 : items[index - 1].endAngle
            if items.count == 1 {
                items[0].ratio = 99.999999 // if ratio <= 100 then crashed. so just input 99.9999
                totalRatio = 100
            }
            item.endAngle = item.startAngle! + (360 * item.ratio / totalRatio).degreesToRadians
            if item.endAngle! > 2 * π {
                item.endAngle = item.endAngle! - 2 * π
            }
        }
    }

But this solution is just a fake. And this is very easy way.

from rkpiechart.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.