Visualisation Revisited playground

I am really suffering about this exercise, but don't know what I am doing wrong( attached screenshots bellow:

Replies

You haven't shown the errors messages. Show what you've tried, what you expected to happen, what actually happened. Please post code as text (formatted as a code block), it makes it easier for us to quote later - screenshots are only useful for graphics.

From the screenshot "makePieChart" creates an instance of a PieChartView named pieChartView". Which suggests there is some code somewhere which calls makePieChart and names the resulting view, like this:

let pieChartView = makePieChart()

"PieChartView has one property named wedges, an array of PieWedgeInstances. Assign an array

pieChartView.wedges = [ PieWedge(proportion: 3, color: .black, scale: 0.5, offset: 0.5),
                                            PieWedge(proportion: 3, color: .black, scale: 0.5, offset: 0.5),
                                            PieWedge(proportion: 3, color: .red) ]

or use the append method of Array to add them one at a time

pieChartView.wedges.append(PieWedge(proportion: 3, color: .black, scale: 0.5, offset: 0.5))
pieChartView.wedges.append(PieWedge(proportion: 3, color: .black, scale: 0.5, offset: 0.5))
pieChartView.wedges.append(PieWedge(proportion: 3, color: .red)

I hope this helps. Stick at it!

@ssmith_c , I have taken a alternative route to the solution but all im getting, in the liveview, is a blank white rectangle and no piechart. Could this be something to do with how I'm calling the makePieChart() Function built into the playground? seems like it has no data to draw the graph from. your advise would be very welcome. Code below

// Create an array of PieWedge instances var wedges: [PieWedge] = []

// Create individual PieWedge instances and add them to the wedges array let wedge1 = PieWedge(proportion: 0.3, color: .red, scale: 1.0, offset: 0) let wedge2 = PieWedge(proportion: 0.2, color: .blue, scale: 0.8, offset: 0.2) let wedge3 = PieWedge(proportion: 0.5, color: .green, scale: 1.2, offset: 0)

wedges.append(wedge1) wedges.append(wedge2) wedges.append(wedge3)

// Create an instance of PieChartView and assign the wedges array let pieChartView = PieChartView() pieChartView.wedges = wedges

// Create an instance of ChartKeyView and configure its keyItems array let keyItem1 = ChartKeyItem(color: .red, name: "Red Wedge") let keyItem2 = ChartKeyItem(color: .blue, name: "Blue Wedge") let keyItem3 = ChartKeyItem(color: .green, name: "Green Wedge") let keyItems = [keyItem1, keyItem2, keyItem3]

let keyView = ChartKeyView() keyView.keyItems = keyItems

makePieChart()

``// Create an array of PieWedge instances var wedges: [PieWedge] = []

// Create individual PieWedge instances and add them to the wedges array
let wedge1 = PieWedge(proportion: 0.3, color: .red, scale: 1.0, offset: 0)
let wedge2 = PieWedge(proportion: 0.2, color: .blue, scale: 0.8, offset: 0.2)
let wedge3 = PieWedge(proportion: 0.5, color: .green, scale: 1.2, offset: 0)

wedges.append(wedge1)
wedges.append(wedge2)
wedges.append(wedge3)

// Create an instance of PieChartView and assign the wedges array
let pieChartView = PieChartView()
pieChartView.wedges = wedges

// Create an instance of ChartKeyView and configure its keyItems array
let keyItem1 = ChartKeyItem(color: .red, name: "Red Wedge")
let keyItem2 = ChartKeyItem(color: .blue, name: "Blue Wedge")
let keyItem3 = ChartKeyItem(color: .green, name: "Green Wedge")
let keyItems = [keyItem1, keyItem2, keyItem3]

let keyView = ChartKeyView()
keyView.keyItems = keyItems

makePieChart ()