xyfeng/XYPieChart — pull request #51 by tcunning (2014-06-07 07:21:00+00:00)
Title: Added support for a Pie Chart Data Source based on a dictionary.

Made it really easy to create a pie chart from a dictionary of entries, and added ability to add a key chart view of the pie chart based on the dictionary.

The following is an example of setting up a pie chart based on a dictionary.

_roundsWonLostPieChartView.colorDict = @{@"Rounds Won": UIColor.redColor, @"Rounds Lost" : UIColor.blackColor };
_roundsWonLostPieChartView.dataSourceDict = @{@"Rounds Won": @(m_playerStats.roundsPlayed - m_playerStats.lostRounds), @"Rounds Lost" : @(m_playerStats.lostRounds)};

_wonPointsInRoundPieChartView.colorDict = @{@"Won 1 Point": UIColor.redColor, @"Won 2 Points" : UIColor.blackColor, @"Won 4 Points" : UIColor.blueColor };
_wonPointsInRoundPieChartView.dataSourceDict = @{@"Won 1 Point": @(m_playerStats.wonRounds1pt), @"Won 2 Points" : @(m_playerStats.wonRounds2pt), @"Won 4 Points" : @(m_playerStats.wonRounds4pt) };
_wonPointsInRoundPieChartView.keyOrder = @[@"Won 1 Point", @"Won 2 Points", @"Won 4 Points"];

The following is an example of dynamically creating a key legend based on the dictionary and adding it to the right of the pie chart.

CGPoint point = CGPointMake( xyPieChartView.frame.origin.x + xyPieChartView.frame.size.width, xyPieChartView.layer.position.y );
UIView *keyView = [xyPieChartView makeLabelKeyViewAtPoint:point boxCornerRadius:2.0];
CGRect frame = keyView.frame;
frame.origin.y -= frame.size.height/2;
keyView.frame = frame;

[_scrollContentsView addSubview:keyView];