Skip to content

Commit

Permalink
Fixed PieChart legend which now shows up correctly and also animates.…
Browse files Browse the repository at this point in the history
… Followed ChartsOrg/Charts#602. Disabled pie chart rotation and also the text does not show up on the pie chart itself now.
  • Loading branch information
senabhishek committed Jul 11, 2016
1 parent bc410d2 commit 79eb836
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions AllAboutMe/AnalyticsPopupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,26 @@ class AnalyticsPopupViewController : UIViewController {
dataPoints.append(contextJson["ctxName"].stringValue)
dataEntries.append(dataEntry)
}
let pieChartDataSet = PieChartDataSet(yVals: dataEntries, label: "\(self.contextGroup!.name)")
let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
self.pieChartView.data = pieChartData
var colors: [UIColor] = []

for _ in 0..<dataPoints.count {
let red = Double(arc4random_uniform(256))
let green = Double(arc4random_uniform(256))
let blue = Double(arc4random_uniform(256))

let color = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1)
colors.append(color)
}

let pieChartDataSet = PieChartDataSet(yVals: dataEntries, label: "\(self.contextGroup!.name)")
let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
pieChartDataSet.colors = colors
self.pieChartView.data = pieChartData
self.pieChartView.rotationEnabled = false
self.pieChartView.drawSliceTextEnabled = false
self.pieChartView.usePercentValuesEnabled = true
let legend:ChartLegend = self.pieChartView.legend
legend.position = ChartLegend.Position.AboveChartCenter
self.pieChartView.animate(xAxisDuration: NSTimeInterval(1.0))
break
}
}
Expand Down
4 changes: 2 additions & 2 deletions AllAboutMe/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="SQu-OU-Cdp" customClass="PieChartView" customModule="Charts">
<rect key="frame" x="20" y="71" width="560" height="509"/>
<rect key="frame" x="20" y="71" width="560" height="521"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rBM-xj-Xgb">
Expand All @@ -455,7 +455,7 @@
<constraints>
<constraint firstItem="nSp-2k-bOo" firstAttribute="top" secondItem="m5s-VB-b1s" secondAttribute="bottom" constant="8" id="3dE-F3-FkK"/>
<constraint firstItem="SQu-OU-Cdp" firstAttribute="top" secondItem="nSp-2k-bOo" secondAttribute="bottom" constant="8" id="9D6-96-JvV"/>
<constraint firstItem="h4h-xP-Puq" firstAttribute="top" secondItem="SQu-OU-Cdp" secondAttribute="bottom" constant="20" id="AxA-2Y-pgV"/>
<constraint firstItem="h4h-xP-Puq" firstAttribute="top" secondItem="SQu-OU-Cdp" secondAttribute="bottom" constant="8" id="AxA-2Y-pgV"/>
<constraint firstItem="SQu-OU-Cdp" firstAttribute="leading" secondItem="zZm-8t-PD5" secondAttribute="leading" constant="20" id="Qwr-bo-Xrt"/>
<constraint firstItem="SQu-OU-Cdp" firstAttribute="top" secondItem="rBM-xj-Xgb" secondAttribute="bottom" constant="8" id="deN-sV-6aE"/>
<constraint firstAttribute="trailing" secondItem="rBM-xj-Xgb" secondAttribute="trailing" constant="8" id="jsb-80-xEd"/>
Expand Down

0 comments on commit 79eb836

Please sign in to comment.