From 675a176bad15d2c5afaa47a52b46ac7938d27d5e Mon Sep 17 00:00:00 2001 From: Jack Wang Date: Tue, 22 Mar 2016 13:10:20 +0800 Subject: [PATCH 1/3] Add PiePolylineChartRenderer --- Charts/Charts.xcodeproj/project.pbxproj | 4 + .../Renderers/PiePolylineChartRenderer.swift | 205 +++++++++++++++++ .../ChartsDemo.xcodeproj/project.pbxproj | 12 +- ChartsDemo/Classes/DemoListViewController.m | 6 + .../Demos/PiePolylineChartViewController.h | 13 ++ .../Demos/PiePolylineChartViewController.m | 209 ++++++++++++++++++ .../Demos/PiePolylineChartViewController.xib | 91 ++++++++ 7 files changed, 539 insertions(+), 1 deletion(-) create mode 100644 Charts/Classes/Renderers/PiePolylineChartRenderer.swift create mode 100644 ChartsDemo/Classes/Demos/PiePolylineChartViewController.h create mode 100644 ChartsDemo/Classes/Demos/PiePolylineChartViewController.m create mode 100644 ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib diff --git a/Charts/Charts.xcodeproj/project.pbxproj b/Charts/Charts.xcodeproj/project.pbxproj index 82aca392a5..3fe843fe76 100644 --- a/Charts/Charts.xcodeproj/project.pbxproj +++ b/Charts/Charts.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0439A34D1C9FF26300496F83 /* PiePolylineChartRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0439A34C1C9FF26300496F83 /* PiePolylineChartRenderer.swift */; }; 06AEE7A71BDC3F8B009875AE /* Charts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BA8EC401A9D14DC00CE82E1 /* Charts.framework */; }; 06AEE7AE1BDC3FC6009875AE /* LineChartTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AEE7AD1BDC3FC6009875AE /* LineChartTests.swift */; }; 06AEE7C21BDC4277009875AE /* FBSnapshotTestCase.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 06AEE7C11BDC4277009875AE /* FBSnapshotTestCase.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -382,6 +383,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0439A34C1C9FF26300496F83 /* PiePolylineChartRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PiePolylineChartRenderer.swift; sourceTree = ""; }; 06AEE7A21BDC3F8B009875AE /* ChartsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ChartsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 06AEE7A61BDC3F8B009875AE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 06AEE7AD1BDC3FC6009875AE /* LineChartTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineChartTests.swift; sourceTree = ""; }; @@ -625,6 +627,7 @@ 5B6A547D1AA5DF1A000F57C2 /* ChartYAxisRenderer.swift */, 5B6A547F1AA5DF28000F57C2 /* ChartYAxisRendererHorizontalBarChart.swift */, 5B6A54811AA5DF34000F57C2 /* ChartYAxisRendererRadarChart.swift */, + 0439A34C1C9FF26300496F83 /* PiePolylineChartRenderer.swift */, ); path = Renderers; sourceTree = ""; @@ -1131,6 +1134,7 @@ 5B680D2A1A9D17C30026A057 /* ChartUtils.swift in Sources */, 659400C81BF463C1004F9C27 /* PieChartDataSet.swift in Sources */, 5B0032451B6524AD00B6A2FE /* ChartHighlight.swift in Sources */, + 0439A34D1C9FF26300496F83 /* PiePolylineChartRenderer.swift in Sources */, 65F06F8E1BE807040074498D /* IChartDataSet.swift in Sources */, 5B680D201A9D17C30026A057 /* ChartLegend.swift in Sources */, 5BCAA7561C7CB0DE00F83F3B /* AnimatedZoomViewJob.swift in Sources */, diff --git a/Charts/Classes/Renderers/PiePolylineChartRenderer.swift b/Charts/Classes/Renderers/PiePolylineChartRenderer.swift new file mode 100644 index 0000000000..031beb2720 --- /dev/null +++ b/Charts/Classes/Renderers/PiePolylineChartRenderer.swift @@ -0,0 +1,205 @@ +// +// PiePolylineChartRenderer.swift +// Charts +// +// Created by Jack Wang on 3/21/16. +// Copyright © 2016 Jack Wang. +// Licensed under Apache License 2.0 +// + +import UIKit + +public class PiePolylineChartRenderer: PieChartRenderer { + public var polylineColor: UIColor? = UIColor.blackColor() + public var polylineWidth: CGFloat = 1.0 + public var polylineLengths: [CGFloat] = [0.1,0.2] + public var enableAdjustPolylineWidth = true; + + + public override func drawValues(context context: CGContext) + { + guard let + chart = chart, + data = chart.data, + animator = animator + else { return } + + let center = chart.centerCircleBox + + // get whole the radius + var r = chart.radius + let rotationAngle = chart.rotationAngle + var drawAngles = chart.drawAngles + var absoluteAngles = chart.absoluteAngles + + let phaseX = animator.phaseX + let phaseY = animator.phaseY + + var off = r / 10.0 * 3.0 + + if chart.drawHoleEnabled + { + off = (r - (r * chart.holeRadiusPercent)) / 2.0 + } + + r -= off; // offset to keep things inside the chart + + var dataSets = data.dataSets + + let yValueSum = (data as! PieChartData).yValueSum + + let drawXVals = chart.isDrawSliceTextEnabled + let usePercentValuesEnabled = chart.usePercentValuesEnabled + + var angle: CGFloat = 0.0 + var xIndex = 0 + + for (var i = 0; i < dataSets.count; i++) + { + guard let dataSet = dataSets[i] as? IPieChartDataSet else { continue } + + let drawYVals = dataSet.isDrawValuesEnabled + + if (!drawYVals && !drawXVals) + { + continue + } + + let valueFont = dataSet.valueFont + + guard let formatter = dataSet.valueFormatter else { continue } + + for (var j = 0, entryCount = dataSet.entryCount; j < entryCount; j++) + { + if (drawXVals && !drawYVals && (j >= data.xValCount || data.xVals[j] == nil)) + { + continue + } + + guard let e = dataSet.entryForIndex(j) else { continue } + + if (xIndex == 0) + { + angle = 0.0 + } + else + { + angle = absoluteAngles[xIndex - 1] * phaseX + } + + let sliceAngle = drawAngles[xIndex] + let sliceSpace = dataSet.sliceSpace + let sliceSpaceMiddleAngle = sliceSpace / (ChartUtils.Math.FDEG2RAD * r) + + // offset needed to center the drawn text in the slice + let offset = (sliceAngle - sliceSpaceMiddleAngle / 2.0) / 2.0 + + angle = angle + offset + + // calculate the text position + let x = r + * cos((rotationAngle + angle * phaseY) * ChartUtils.Math.FDEG2RAD) + + center.x + var y = r + * sin((rotationAngle + angle * phaseY) * ChartUtils.Math.FDEG2RAD) + + center.y + + let angle = rotationAngle + absoluteAngles[xIndex] - offset; + + let x1 = (r * (1 + polylineLengths[0]) + * cos((angle * phaseY) * ChartUtils.Math.FDEG2RAD) + center.x) + let y1 = (r * (1 + polylineLengths[0]) + * sin((angle * phaseY) * ChartUtils.Math.FDEG2RAD) + center.y) + + let value = usePercentValuesEnabled ? e.value / yValueSum * 100.0 : e.value + + let val = formatter.stringFromNumber(value)! + + let lineHeight = valueFont.lineHeight + y -= lineHeight + + //draw polyline + var startPoint:CGPoint, midPoint:CGPoint, endPoint:CGPoint, labelPoint:CGPoint + var align:NSTextAlignment + let polyline2Width = enableAdjustPolylineWidth + ? r * polylineLengths[1] * abs(sin(angle * ChartUtils.Math.FDEG2RAD)) + : r * polylineLengths[1]; + + startPoint = CGPoint(x: x, y: y + lineHeight); + midPoint = CGPoint(x: x1, y: y1) + + if(angle%360 >= 90 && angle%360 <= 270) { + endPoint = CGPoint(x: x1 - polyline2Width, y: y1) + align = .Right + labelPoint = CGPoint(x: endPoint.x - 5, y: endPoint.y - lineHeight) + } else { + endPoint = CGPoint(x: x1 + polyline2Width, y: y1) + align = .Left + labelPoint = CGPoint(x: endPoint.x + 5, y: endPoint.y - lineHeight) + } + + self.drawPolyline(context: context, startPoint: startPoint, midPoint: midPoint, endPoint: endPoint) + + // draw everything, depending on settings + if (drawXVals && drawYVals) + { + ChartUtils.drawText( + context: context, + text: val, + point: labelPoint, + align: align, + attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: dataSet.valueTextColorAt(j)] + ) + + if (j < data.xValCount && data.xVals[j] != nil) + { + ChartUtils.drawText( + context: context, + text: data.xVals[j]!, + point: CGPoint(x: labelPoint.x, y: labelPoint.y + lineHeight), + align: align, + attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: dataSet.valueTextColorAt(j)] + ) + } + } + else if (drawXVals) + { + ChartUtils.drawText( + context: context, + text: data.xVals[j]!, + point: CGPoint(x: labelPoint.x, y: labelPoint.y + lineHeight / 2.0), + align: align, + attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: dataSet.valueTextColorAt(j)] + ) + } + else if (drawYVals) + { + ChartUtils.drawText( + context: context, + text: val, + point: CGPoint(x: labelPoint.x, y: labelPoint.y + lineHeight / 2.0), + align: align, + attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: dataSet.valueTextColorAt(j)] + ) + } + + xIndex++ + } + } + } + + public func drawPolyline(context context:CGContextRef, startPoint:CGPoint, midPoint:CGPoint, endPoint:CGPoint) { + CGContextSaveGState(context) + + // draw the hole-circle + CGContextSetStrokeColorWithColor(context, UIColor.blackColor().CGColor) + CGContextSetLineWidth(context, 1.0); + + CGContextMoveToPoint(context, startPoint.x, startPoint.y) + CGContextAddLineToPoint(context, midPoint.x, midPoint.y) + CGContextAddLineToPoint(context, endPoint.x, endPoint.y) + + CGContextDrawPath(context, CGPathDrawingMode.Stroke); + CGContextRestoreGState(context) + } +} diff --git a/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj b/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj index ee3e08d2a9..314d7ec2a3 100644 --- a/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj +++ b/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 0439A3541C9FF95F00496F83 /* PiePolylineChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0439A3521C9FF95F00496F83 /* PiePolylineChartViewController.m */; }; + 0471CBFC1CA1090A00E52DBC /* PiePolylineChartViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0471CBFB1CA1090A00E52DBC /* PiePolylineChartViewController.xib */; }; 55E356501ADC638F00A57971 /* BubbleChartViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55E3564D1ADC638F00A57971 /* BubbleChartViewController.xib */; }; 55E356511ADC638F00A57971 /* BubbleChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 55E3564F1ADC638F00A57971 /* BubbleChartViewController.m */; }; 5B0CC7851ABB875400665592 /* PieChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B0CC7831ABB875400665592 /* PieChartViewController.m */; }; @@ -173,6 +175,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0439A3511C9FF95F00496F83 /* PiePolylineChartViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PiePolylineChartViewController.h; sourceTree = ""; }; + 0439A3521C9FF95F00496F83 /* PiePolylineChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PiePolylineChartViewController.m; sourceTree = ""; }; + 0471CBFB1CA1090A00E52DBC /* PiePolylineChartViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PiePolylineChartViewController.xib; sourceTree = ""; }; 55E3564D1ADC638F00A57971 /* BubbleChartViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BubbleChartViewController.xib; sourceTree = ""; }; 55E3564E1ADC638F00A57971 /* BubbleChartViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BubbleChartViewController.h; sourceTree = ""; }; 55E3564F1ADC638F00A57971 /* BubbleChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BubbleChartViewController.m; sourceTree = ""; }; @@ -397,8 +402,8 @@ children = ( 5B8E087E1C635B5200438BAF /* Charts.framework */, 5B8E08801C635B5200438BAF /* Charts.framework */, - 5B8E08821C635B5200438BAF /* ChartsTests.xctest */, 65B3F6571C73B4F6000983D0 /* Charts.framework */, + 5B8E08821C635B5200438BAF /* ChartsTests.xctest */, ); name = Products; sourceTree = ""; @@ -477,6 +482,9 @@ 5B0CC7821ABB875400665592 /* PieChartViewController.h */, 5B0CC7831ABB875400665592 /* PieChartViewController.m */, 5B0CC7841ABB875400665592 /* PieChartViewController.xib */, + 0439A3511C9FF95F00496F83 /* PiePolylineChartViewController.h */, + 0439A3521C9FF95F00496F83 /* PiePolylineChartViewController.m */, + 0471CBFB1CA1090A00E52DBC /* PiePolylineChartViewController.xib */, 5BE7E75F1C693098000A0377 /* PositiveNegativeBarChartViewController.h */, 5BE7E7601C693098000A0377 /* PositiveNegativeBarChartViewController.m */, 5BE7E7611C693098000A0377 /* PositiveNegativeBarChartViewController.xib */, @@ -696,6 +704,7 @@ 5B0CC7861ABB875400665592 /* PieChartViewController.xib in Resources */, 5B7B3AE01C437F61001C109B /* RealmCandleChartViewController.xib in Resources */, 5BEAED1C1ABBFB340013F194 /* ScatterChartViewController.xib in Resources */, + 0471CBFC1CA1090A00E52DBC /* PiePolylineChartViewController.xib in Resources */, 5BD8F0751AB89CE500566E05 /* LineChart1ViewController.xib in Resources */, 5B43162D1AB8D8AE0009FCAA /* iTunesArtwork in Resources */, 65BF12B11BFC9B00005C28D9 /* RealmLineChartViewController.xib in Resources */, @@ -727,6 +736,7 @@ 5B4AC19E1C4C19340028D1A6 /* RealmWikiExampleChartViewController.m in Sources */, 5B4AC1561C47EDC50028D1A6 /* RealmRadarChartViewController.m in Sources */, 5B0CC7851ABB875400665592 /* PieChartViewController.m in Sources */, + 0439A3541C9FF95F00496F83 /* PiePolylineChartViewController.m in Sources */, 5B57BBBB1A9B26AA0036A6CC /* DemoListViewController.m in Sources */, 5BD47E651ABB424E008FCEC6 /* BarChartViewController.m in Sources */, 5BDEDC471ABB871E007D3A60 /* CombinedChartViewController.m in Sources */, diff --git a/ChartsDemo/Classes/DemoListViewController.m b/ChartsDemo/Classes/DemoListViewController.m index cc5df68012..06ad990a0a 100644 --- a/ChartsDemo/Classes/DemoListViewController.m +++ b/ChartsDemo/Classes/DemoListViewController.m @@ -18,6 +18,7 @@ #import "HorizontalBarChartViewController.h" #import "CombinedChartViewController.h" #import "PieChartViewController.h" +#import "PiePolylineChartViewController.h" #import "ScatterChartViewController.h" #import "StackedBarChartViewController.h" #import "NegativeStackedBarChartViewController.h" @@ -78,6 +79,11 @@ - (void)viewDidLoad @"subtitle": @"A simple demonstration of the pie chart.", @"class": PieChartViewController.class }, + @{ + @"title": @"Pie Polyline Chart", + @"subtitle": @"A simple demonstration of the pie chart with polyline notes.", + @"class": PiePolylineChartViewController.class + }, @{ @"title": @"Scatter Chart", @"subtitle": @"A simple demonstration of the scatter chart.", diff --git a/ChartsDemo/Classes/Demos/PiePolylineChartViewController.h b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.h new file mode 100644 index 0000000000..1ee0f4d1b5 --- /dev/null +++ b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.h @@ -0,0 +1,13 @@ +// +// PiePolylineChartViewController.h +// ChartsDemo +// +// Created by Jack Wang on 3/21/16. +// Copyright © 2016 Jack Wang +// + +#import "PieChartViewController.h" + +@interface PiePolylineChartViewController : DemoBaseViewController + +@end diff --git a/ChartsDemo/Classes/Demos/PiePolylineChartViewController.m b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.m new file mode 100644 index 0000000000..4d2c78fed8 --- /dev/null +++ b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.m @@ -0,0 +1,209 @@ +// +// PiePolylineChartViewController.h +// ChartsDemo +// +// Created by Jack Wang on 3/21/16. +// Copyright © 2016 Jack Wang +// + +#import "PiePolylineChartViewController.h" +#import "ChartsDemo-Swift.h" + +@interface PiePolylineChartViewController () + +@property (nonatomic, strong) IBOutlet PieChartView *chartView; +@property (nonatomic, strong) IBOutlet UISlider *sliderX; +@property (nonatomic, strong) IBOutlet UISlider *sliderY; +@property (nonatomic, strong) IBOutlet UITextField *sliderTextX; +@property (nonatomic, strong) IBOutlet UITextField *sliderTextY; +@end + +@implementation PiePolylineChartViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.title = @"Pie Bar Chart"; + + self.options = @[ + @{@"key": @"toggleValues", @"label": @"Toggle Y-Values"}, + @{@"key": @"toggleXValues", @"label": @"Toggle X-Values"}, + @{@"key": @"togglePercent", @"label": @"Toggle Percent"}, + @{@"key": @"toggleHole", @"label": @"Toggle Hole"}, + @{@"key": @"animateX", @"label": @"Animate X"}, + @{@"key": @"animateY", @"label": @"Animate Y"}, + @{@"key": @"animateXY", @"label": @"Animate XY"}, + @{@"key": @"spin", @"label": @"Spin"}, + @{@"key": @"drawCenter", @"label": @"Draw CenterText"}, + @{@"key": @"saveToGallery", @"label": @"Save to Camera Roll"}, + @{@"key": @"toggleData", @"label": @"Toggle Data"}, + ]; + + [self setupPieChartView:_chartView]; + + PiePolylineChartRenderer *pieChartRender = [[PiePolylineChartRenderer alloc] initWithChart:self.chartView animator:self.chartView.chartAnimator viewPortHandler:self.chartView.viewPortHandler]; + pieChartRender.polylineLengths = @[@0.4, @0.5]; + self.chartView.renderer = pieChartRender; + + _chartView.legend.enabled = NO; + _chartView.delegate = self; + + _sliderX.value = 3.0; + _sliderY.value = 100.0; + [self slidersValueChanged:nil]; + + [_chartView animateWithYAxisDuration:1.4 easingOption:ChartEasingOptionEaseOutBack]; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (void)updateChartData +{ + if (self.shouldHideData) + { + _chartView.data = nil; + return; + } + + [self setDataCount:(_sliderX.value + 1) range:_sliderY.value]; +} + +- (void)setDataCount:(int)count range:(double)range +{ + double mult = range; + + NSMutableArray *yVals1 = [[NSMutableArray alloc] init]; + + // IMPORTANT: In a PieChart, no values (Entry) should have the same xIndex (even if from different DataSets), since no values can be drawn above each other. + for (int i = 0; i < count; i++) + { + [yVals1 addObject:[[BarChartDataEntry alloc] initWithValue:(arc4random_uniform(mult) + mult / 5) xIndex:i]]; + } + + NSMutableArray *xVals = [[NSMutableArray alloc] init]; + + for (int i = 0; i < count; i++) + { + [xVals addObject:parties[i % parties.count]]; + } + + PieChartDataSet *dataSet = [[PieChartDataSet alloc] initWithYVals:yVals1 label:@"Election Results"]; + dataSet.sliceSpace = 2.0; + + // add a lot of colors + + NSMutableArray *colors = [[NSMutableArray alloc] init]; + [colors addObjectsFromArray:ChartColorTemplates.vordiplom]; + [colors addObjectsFromArray:ChartColorTemplates.joyful]; + [colors addObjectsFromArray:ChartColorTemplates.colorful]; + [colors addObjectsFromArray:ChartColorTemplates.liberty]; + [colors addObjectsFromArray:ChartColorTemplates.pastel]; + [colors addObject:[UIColor colorWithRed:51/255.f green:181/255.f blue:229/255.f alpha:1.f]]; + + dataSet.colors = colors; + + PieChartData *data = [[PieChartData alloc] initWithXVals:xVals dataSet:dataSet]; + + NSNumberFormatter *pFormatter = [[NSNumberFormatter alloc] init]; + pFormatter.numberStyle = NSNumberFormatterPercentStyle; + pFormatter.maximumFractionDigits = 1; + pFormatter.multiplier = @1.f; + pFormatter.percentSymbol = @" %"; + [data setValueFormatter:pFormatter]; + [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:11.f]]; + [data setValueTextColor:UIColor.blackColor]; + + _chartView.data = data; + [_chartView highlightValues:nil]; +} + +- (void)optionTapped:(NSString *)key +{ + if ([key isEqualToString:@"toggleXValues"]) + { + _chartView.drawSliceTextEnabled = !_chartView.isDrawSliceTextEnabled; + + [_chartView setNeedsDisplay]; + return; + } + + if ([key isEqualToString:@"togglePercent"]) + { + _chartView.usePercentValuesEnabled = !_chartView.isUsePercentValuesEnabled; + + [_chartView setNeedsDisplay]; + return; + } + + if ([key isEqualToString:@"toggleHole"]) + { + _chartView.drawHoleEnabled = !_chartView.isDrawHoleEnabled; + + [_chartView setNeedsDisplay]; + return; + } + + if ([key isEqualToString:@"drawCenter"]) + { + _chartView.drawCenterTextEnabled = !_chartView.isDrawCenterTextEnabled; + + [_chartView setNeedsDisplay]; + return; + } + + if ([key isEqualToString:@"animateX"]) + { + [_chartView animateWithXAxisDuration:1.4]; + return; + } + + if ([key isEqualToString:@"animateY"]) + { + [_chartView animateWithYAxisDuration:1.4]; + return; + } + + if ([key isEqualToString:@"animateXY"]) + { + [_chartView animateWithXAxisDuration:1.4 yAxisDuration:1.4]; + return; + } + + if ([key isEqualToString:@"spin"]) + { + [_chartView spinWithDuration:2.0 fromAngle:_chartView.rotationAngle toAngle:_chartView.rotationAngle + 360.f]; + return; + } + + [super handleOption:key forChartView:_chartView]; +} + +#pragma mark - Actions + +- (IBAction)slidersValueChanged:(id)sender +{ + _sliderTextX.text = [@((int)_sliderX.value + 1) stringValue]; + _sliderTextY.text = [@((int)_sliderY.value) stringValue]; + + [self updateChartData]; +} + +#pragma mark - ChartViewDelegate + +- (void)chartValueSelected:(ChartViewBase * __nonnull)chartView entry:(ChartDataEntry * __nonnull)entry dataSetIndex:(NSInteger)dataSetIndex highlight:(ChartHighlight * __nonnull)highlight +{ + NSLog(@"chartValueSelected"); +} + +- (void)chartValueNothingSelected:(ChartViewBase * __nonnull)chartView +{ + NSLog(@"chartValueNothingSelected"); +} + +@end + diff --git a/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib new file mode 100644 index 0000000000..756cdb89f6 --- /dev/null +++ b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 6afcc3746b3ae01943ed349cc6f53a15e60a017b Mon Sep 17 00:00:00 2001 From: Jack Wang Date: Tue, 22 Mar 2016 16:38:30 +0800 Subject: [PATCH 2/3] update xib outlet reference --- .../Demos/PiePolylineChartViewController.xib | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib index 756cdb89f6..9d13e9e975 100644 --- a/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib +++ b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib @@ -8,10 +8,10 @@ - - - - + + + + @@ -37,9 +37,15 @@ + + + + + + From d078986784e5d1dcc4c988019b995f5b57383d38 Mon Sep 17 00:00:00 2001 From: Jack Wang Date: Tue, 22 Mar 2016 16:47:54 +0800 Subject: [PATCH 3/3] update xib outlet reference --- ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib index 9d13e9e975..31fbc8b8f7 100644 --- a/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib +++ b/ChartsDemo/Classes/Demos/PiePolylineChartViewController.xib @@ -27,6 +27,9 @@ + + +