Code Monkey home page Code Monkey logo

Comments (4)

zas9vf avatar zas9vf commented on August 26, 2024 1

hey @karzler. im having the issue where the old labels aren't getting removed. Im using a redux like approach when updating my pie chart but for some reason, the old labels won't go away. This is what i have:

    chartView.models.removeAll()
    chartView.removeSlices()
    chartView.layers.removeAll()
    
    self.chartView.models = state.pieSlices


    chartView.layers = [createTextLayer()] <- this function creates new labels with updated values

how'd you remove the old labels?

I'd appreciate the help here

from piecharts.

karzler avatar karzler commented on August 26, 2024

Apparently, it was a tiny mistake on my side. I was recreating text layers multiple times.

For folks looking out how to update the chart, simple set models to empty, and then create models again. Make sure you remove the slices before creating the new models

from piecharts.

yh2015 avatar yh2015 commented on August 26, 2024

Hey @zas9vf, I struggled a bit to remove the old labels. In my case I used

self.chartView.removeSlices()
self.chartView.layers.removeAll()
self.chartView.models.removeAll()

and initialized text layer as a global variable in the page

var textLayer = PiePlainTextLayer()

Each time i needed to update the chart i used this code:

self.textLayer.clear()

Then update the layers using the method that exists in the tutorial

 let textLayerSettings = PiePlainTextLayerSettings()
 textLayerSettings.viewRadius = 100
 textLayerSettings.hideOnOverflow = false
 textLayerSettings.label.textColor = UIColor.white
 textLayerSettings.label.font = UIFont.systemFont(ofSize: 15)
                                
 let formatter = NumberFormatter()
 formatter.maximumFractionDigits = 1
 textLayerSettings.label.textGenerator = {slice in
    return formatter.string(from: slice.data.percentage * 100 as NSNumber).map{_ 
    }
}
self.textLayer.settings = textLayerSettings
self.chartView.layers = [self.textLayer]

I hope this helps.

from piecharts.

zas9vf avatar zas9vf commented on August 26, 2024

I had to do some edits to the source code itself to get what I wanted but appreciate the help! 👍🏽

from piecharts.

Related Issues (20)

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.