Swift: Donut Chart doesn't fit with it's View


#1

I stuck for this problem from days. I have two subview with two donut chart. I’m using Auto Layout in Ipad 9.7 and its work on Ipad Air, Air 2 and retina. But the view being messy in Ipad 12.9 . Here the screenshoot :

  • picture above run on Ipad 9.7

  • picture above run on Ipad 12.9

The UIView’s are resizing based on their constraint but not with the donut. Here my setup for donut :

 func setupDonut(_ donut: ShinobiChart, viewForDonut: UIView) {
    donut.frame = CGRect.init(x: (0), y: (0), width: viewForDonut.bounds.size.width, height: viewForDonut.bounds.size.height)
    
    donut.legend.isHidden = false
    donut.titleLabel.font = UIFont.boldSystemFont(ofSize: 15)
    donut.titleLabel.numberOfLines = 0
    donut.titleLabel.lineBreakMode = .byWordWrapping
    
    donut.legend.isHidden = true

    viewForDonut.addSubview(donut)
   
    donut.delegate = self
    donut.datasource = self
}

Do I do a mistake? I have try sizeToFit , sizeToFits(size:) but not working. Any advise and answer will help for me. Thanks in advance.

Best,
X


#2

Hi MrX,

Please could you provide some more information so we can help you?

  • Are you creating the chart objects in code or via Interface Builder? Could you provide the code if that’s how you’re creating them?
  • What layout constraints/autoresizing settings have you set on the chart, and on viewForDonut?
  • Have you checked whether viewForDonut is the size you expect before you set the chart’s frame?

Kind regards,

Alison


#3

Hi aclarke,

I create the chart object in code, code above is how I create the chart, there is nothing else. In viewForDonut, I only set top, bottom, right and left constraint, and nothing else too. As you can see, the view’s are scale based on superview (display of Ipad) and I have try to set width and height of chart manually (width 400 and height 400 or etc) but the chart still stuck on Ipad 9.7 size.

Best,
X


#4

Hi MrX,

It’s hard to help you without knowing more about how the views are created and laid out, and at what point you’re resizing the chart’s frame. Perhaps you could email the zipped-up project to us at info@shinobicontrols.com along with your support key?

Kind regards,

Alison