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

No plot showing up #2

Open
Liyun-Yang opened this issue Feb 27, 2015 · 5 comments
Open

No plot showing up #2

Liyun-Yang opened this issue Feb 27, 2015 · 5 comments

Comments

@Liyun-Yang
Copy link

Hi,

I tried to link the pieChartView to a UIView I created, but the codes didn't work.
How can I use this to draw a pie chart in the view controller?

The code I added in my app is:

@IBOutlet weak var pieChartView: PieChartView!

pieChartView.addItem(20, color: UIColor.blueColor())
pieChartView.addItem(20, color: UIColor.redColor())
pieChartView.addItem(60, color: UIColor.purpleColor())

@vitobellini
Copy link
Owner

you have to redraw the view

pieChartView.setNeedsDisplay()

Dott. Vito Bellini

Mobile: (+39) 348 8908593
[email protected]
http://www.vitobellini.com

Il giorno 27/feb/2015, alle ore 13:59, mushroomcloudy [email protected] ha scritto:

Hi,

I tried to link the pieChartView to a UIView I created, but the codes didn't work.
How can I use this to draw a pie chart in the view controller?

The code I added in my app is:

@IBOutlet weak var pieChartView: PieChartView!

pieChartView.addItem(20, color: UIColor.blueColor())
pieChartView.addItem(20, color: UIColor.redColor())
pieChartView.addItem(60, color: UIColor.purpleColor())


Reply to this email directly or view it on GitHub #2.

@Liyun-Yang
Copy link
Author

Hi!

Thanks for replying.

I add the line but it still didn't show up. It seems after I set its class to pieChartView, then it didn't show in the interface after I ran the app. I tried to set the colour to grey but there was nothing at all. The other labels were showing up normally.

@vitobellini
Copy link
Owner

Have you created the UIView programmatically or via IB?
I’ve just created a playground file to check it out and it seems to work

Dott. Vito Bellini

Mobile: (+39) 348 8908593
[email protected]
http://www.vitobellini.com

Il giorno 27/feb/2015, alle ore 17:14, mushroomcloudy [email protected] ha scritto:

Hi!

Thanks for replying.

I add the line but it still didn't show up. It seems after I set its class to pieChartView, then it didn't show in the interface after I ran the app. I tried to set the colour to grey but there was nothing at all. The other labels were showing up normally.


Reply to this email directly or view it on GitHub #2 (comment).

@Liyun-Yang
Copy link
Author

Hi,

I created a View from storyboard and then linked it to the file. I also changed it in the identification column from UIView to PieChartView.

and then follows
pieChartView.addItem(20, color: UIColor.redColor())
pieChartView.addItem(20, color: UIColor.greenColor())
pieChartView.addItem(60, color: UIColor.brownColor())
pieChartView.setNeedsDisplay()

It still didn’t show up...

Hope you have a nice weekend!

On 27 Feb 2015, at 17:21, Vito Bellini [email protected] wrote:

Have you created the UIView programmatically or via IB?
I’ve just created a playground file to check it out and it seems to work

Dott. Vito Bellini

Mobile: (+39) 348 8908593
[email protected]
http://www.vitobellini.com

Il giorno 27/feb/2015, alle ore 17:14, mushroomcloudy [email protected] ha scritto:

Hi!

Thanks for replying.

I add the line but it still didn't show up. It seems after I set its class to pieChartView, then it didn't show in the interface after I ran the app. I tried to set the colour to grey but there was nothing at all. The other labels were showing up normally.


Reply to this email directly or view it on GitHub #2 (comment).


Reply to this email directly or view it on GitHub.

@nyisztor
Copy link

Hi,

Had the same issue. The root cause is that the overidden drawRect is not being called when assigning the PiechartView directly to the IBOutlet. This usually happens when the views frame is invalid (CGRectZero); however, the views frame was set correctly, so the problem must be something else.

Solution
Make your storyboard IBOutlet a normal UIView, then add the piechart as a subview to it.
This is how I did - note that statsView is a UIView added to my custom table view cell's content view:

    let pieChart = PieChartView(frame: CGRectMake(0, 0, cell.statsView.frame.width, cell.statsView.frame.height))
    cell.statsView.addSubview(pieChart)        
    pieChart.addItem(20, color: UIColor.redColor())
    pieChart.addItem(20, color: UIColor.greenColor())
    pieChart.addItem(60, color: UIColor.brownColor())
    pieChart.setNeedsDisplay()

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