diff --git a/Charts/Charts.xcodeproj/project.pbxproj b/Charts/Charts.xcodeproj/project.pbxproj index 01c745bee4..e28b980fd7 100644 --- a/Charts/Charts.xcodeproj/project.pbxproj +++ b/Charts/Charts.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 13D38A561B709EB0009D4C4D /* CombinedChartHighlighter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13D38A551B709EB0009D4C4D /* CombinedChartHighlighter.swift */; }; 55E356531ADC63BF00A57971 /* BubbleChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E356521ADC63BF00A57971 /* BubbleChartView.swift */; }; 55E356571ADC63CD00A57971 /* BubbleChartData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E356541ADC63CD00A57971 /* BubbleChartData.swift */; }; 55E356581ADC63CD00A57971 /* BubbleChartDataEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E356551ADC63CD00A57971 /* BubbleChartDataEntry.swift */; }; @@ -93,6 +94,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 13D38A551B709EB0009D4C4D /* CombinedChartHighlighter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CombinedChartHighlighter.swift; sourceTree = ""; }; 55E356521ADC63BF00A57971 /* BubbleChartView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartView.swift; sourceTree = ""; }; 55E356541ADC63CD00A57971 /* BubbleChartData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartData.swift; sourceTree = ""; }; 55E356551ADC63CD00A57971 /* BubbleChartDataEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BubbleChartDataEntry.swift; sourceTree = ""; }; @@ -198,6 +200,7 @@ 5B0032441B6524AD00B6A2FE /* ChartHighlight.swift */, 5B0032461B6524D300B6A2FE /* ChartRange.swift */, 5B0032481B6525FC00B6A2FE /* ChartHighlighter.swift */, + 13D38A551B709EB0009D4C4D /* CombinedChartHighlighter.swift */, 5B00324A1B652BF900B6A2FE /* BarChartHighlighter.swift */, 5B00324C1B65351C00B6A2FE /* HorizontalBarChartHighlighter.swift */, ); @@ -482,6 +485,7 @@ 5B680D231A9D17C30026A057 /* ChartYAxis.swift in Sources */, 5B6A54A91AA66BBA000F57C2 /* RadarChartView.swift in Sources */, 5B378F171AD500A4009414A4 /* ChartAnimationEasing.swift in Sources */, + 13D38A561B709EB0009D4C4D /* CombinedChartHighlighter.swift in Sources */, 5B6A548F1AA66A7A000F57C2 /* HorizontalBarChartRenderer.swift in Sources */, 5B6A54741AA5DEDC000F57C2 /* ChartXAxisRenderer.swift in Sources */, 5B6A547C1AA5DF02000F57C2 /* ChartXAxisRendererHorizontalBarChart.swift in Sources */, diff --git a/Charts/Classes/Charts/BarLineChartViewBase.swift b/Charts/Classes/Charts/BarLineChartViewBase.swift index 82674f2515..64a76cb4d3 100644 --- a/Charts/Classes/Charts/BarLineChartViewBase.swift +++ b/Charts/Classes/Charts/BarLineChartViewBase.swift @@ -13,7 +13,7 @@ import Foundation import CoreGraphics -import UIKit.UIGestureRecognizer +import UIKit /// Base-class of LineChart, BarChart, ScatterChart and CandleStickChart. public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate diff --git a/Charts/Classes/Charts/CombinedChartView.swift b/Charts/Classes/Charts/CombinedChartView.swift index 2eaef4fcf3..31c53dea41 100644 --- a/Charts/Classes/Charts/CombinedChartView.swift +++ b/Charts/Classes/Charts/CombinedChartView.swift @@ -20,6 +20,16 @@ public class CombinedChartView: BarLineChartViewBase /// the fill-formatter used for determining the position of the fill-line internal var _fillFormatter: ChartFillFormatter! + internal var _barChartXMax = Double(0.0) + internal var _barChartXMin = Double(0.0) + internal var _barChartDeltaX = CGFloat(0.0) + + internal var _barChartLeftYAxisRenderer: ChartYAxisRenderer! + internal var _barChartRightYAxisRenderer: ChartYAxisRenderer! + + internal var _barChartLeftAxisTransformer: ChartTransformer! + internal var _barChartRightAxisTransformer: ChartTransformer! + /// enum that allows to specify the order in which the different data objects for the combined-chart are drawn @objc public enum CombinedChartDrawOrder: Int @@ -37,7 +47,15 @@ public class CombinedChartView: BarLineChartViewBase _fillFormatter = BarLineChartFillFormatter(chart: self) + _barChartLeftAxisTransformer = ChartTransformer(viewPortHandler: _viewPortHandler) + _barChartRightAxisTransformer = ChartTransformer(viewPortHandler: _viewPortHandler) + + _barChartLeftYAxisRenderer = ChartYAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: _leftAxis, transformer: _leftAxisTransformer) + _barChartRightYAxisRenderer = ChartYAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: _rightAxis, transformer: _rightAxisTransformer) + renderer = CombinedChartRenderer(chart: self, animator: _animator, viewPortHandler: _viewPortHandler) + + _highlighter = CombinedChartHighlighter(chart: self) } override func calcMinMax() @@ -72,11 +90,62 @@ public class CombinedChartView: BarLineChartViewBase _chartXMin = 0.0 _chartXMax = Double(_data.xValCount - 1) } + + if (self.barData !== nil) + { + var barData = self.barData + + _barChartXMin = _chartXMin + _barChartXMax = _chartXMax + _barChartDeltaX = _deltaX + // increase deltax by 1 because the bars have a width of 1 + _barChartDeltaX += 0.5 + + // extend xDelta to make space for multiple datasets (if ther are one) + _barChartDeltaX *= CGFloat(barData.dataSetCount) + + var maxEntry = _data.xValCount + + var groupSpace = barData.groupSpace + _barChartDeltaX += CGFloat(maxEntry) * groupSpace + _barChartXMax = Double(_barChartDeltaX) - _barChartXMin + } _deltaX = CGFloat(abs(_chartXMax - _chartXMin)) } } + internal override func prepareValuePxMatrix() + { + super.prepareValuePxMatrix() + + _barChartRightAxisTransformer.prepareMatrixValuePx(chartXMin: _barChartXMin, deltaX: _barChartDeltaX, deltaY: CGFloat(_rightAxis.axisRange), chartYMin: _rightAxis.axisMinimum) + _barChartLeftAxisTransformer.prepareMatrixValuePx(chartXMin: _barChartXMin, deltaX: _barChartDeltaX, deltaY: CGFloat(_leftAxis.axisRange), chartYMin: _leftAxis.axisMinimum) + } + + internal override func prepareOffsetMatrix() + { + super.prepareOffsetMatrix() + + _barChartRightAxisTransformer.prepareMatrixOffset(_rightAxis.isInverted) + _barChartLeftAxisTransformer.prepareMatrixOffset(_leftAxis.isInverted) + } + + /// Returns the Transformer class that contains all matrices and is + /// responsible for transforming values into pixels on the screen and + /// backwards. + public func getBarChartTransformer(which: ChartYAxis.AxisDependency) -> ChartTransformer + { + if (which == .Left) + { + return _barChartLeftAxisTransformer + } + else + { + return _barChartRightAxisTransformer + } + } + public override var data: ChartData? { get diff --git a/Charts/Classes/Highlight/CombinedChartHighlighter.swift b/Charts/Classes/Highlight/CombinedChartHighlighter.swift new file mode 100644 index 0000000000..f9759ad166 --- /dev/null +++ b/Charts/Classes/Highlight/CombinedChartHighlighter.swift @@ -0,0 +1,271 @@ +// +// CombinedChartHighlighter.swift +// Charts +// +// Created by Xuan on 8/3/15. +// +// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda & Xuan Liu +// A port of MPAndroidChart for iOS +// Licensed under Apache License 2.0 +// +// https://github.com/danielgindi/ios-charts +// + +import Foundation + +internal class CombinedChartHighlighter: ChartHighlighter +{ + internal init(chart: CombinedChartView) + { + super.init(chart: chart) + } + + internal override func getHighlight(#x: Double, y: Double) -> ChartHighlight? + { + var h: ChartHighlight? + + h = super.getHighlight(x: x, y: y) + + if h === nil + { + return h + } + else + { + if let set = _chart?.data?.getDataSetByIndex(h!.dataSetIndex) as? BarChartDataSet + { + if set.isStacked + { + // caeate an array of the touch-point + var pt = CGPoint() + pt.y = CGFloat(y) + + // take the barChartTransformer from CombinedChartView to determine the x-axis value + (_chart as? CombinedChartView)?.getBarChartTransformer(set.axisDependency).pixelToValue(&pt) + + return getStackedHighlight(old: h, set: set, xIndex: h!.xIndex, dataSetIndex: h!.dataSetIndex, yValue: Double(pt.y)) + } + else + { + + } + } + + return h + } + } + + /// Returns the corresponding x-index for a given touch-position in pixels. + /// :param: x + /// :returns: + internal override func getXIndex(x: Double) -> Int + { + if let barData = (_chart as? CombinedChartView)?.barData + { + if !barData.isGrouped + { + return super.getXIndex(x) + } + else + { + let baseNoSpace = getBase(x) + + let setCount = barData.dataSetCount + var xIndex = Int(baseNoSpace) / setCount + + if let valCount = _chart?.data?.xValCount + { + if xIndex < 0 + { + xIndex = 0 + } + else if xIndex >= valCount + { + xIndex = valCount - 1 + } + + return xIndex + } + else + { + return -Int.max + } + } + } + + return super.getXIndex(x) + } + + /** + get dataSetIndex for bars + + :param: xIndex Int + :param: x Double + :param: y Double + + :returns: Int + */ + internal override func getDataSetIndex(#xIndex: Int, x: Double, y: Double) -> Int + { + if let barData = (_chart as? CombinedChartView)?.barData + { + if !barData.isGrouped + { + return 0 + } + else + { + let baseNoSpace = getBase(x) + + let setCount = barData.dataSetCount + var dataSetIndex = Int(baseNoSpace) % setCount + + if dataSetIndex < 0 + { + dataSetIndex = 0 + } + else if dataSetIndex >= setCount + { + dataSetIndex = setCount - 1 + } + + return dataSetIndex + } + } + else + { + return 0 + } + } + + /// Same as BarChartHighlighter.getStackedHighlight() + /// Whatever changed in BarChartHighlighter.getStackedHighlight() should also be applied here + /// This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected. + /// :param: old the old highlight object before looking for stacked values + /// :param: set + /// :param: xIndex + /// :param: dataSetIndex + /// :param: yValue + /// :returns: + internal func getStackedHighlight(#old: ChartHighlight?, set: BarChartDataSet, xIndex: Int, dataSetIndex: Int, yValue: Double) -> ChartHighlight? + { + var entry = set.entryForXIndex(xIndex) as? BarChartDataEntry + + if entry?.values === nil + { + return old + } + + if let ranges = getRanges(entry: entry!) + { + let stackIndex = getClosestStackIndex(ranges: ranges, value: yValue) + let h = ChartHighlight(xIndex: xIndex, dataSetIndex: dataSetIndex, stackIndex: stackIndex, range: ranges[stackIndex]) + return h + } + return nil + } + + /// Same as BarChartHighlighter.getClosestStackIndex() + /// Whatever changed in BarChartHighlighter.getClosestStackIndex() should also be applied here + /// Returns the index of the closest value inside the values array / ranges (stacked barchart) to the value given as a parameter. + /// :param: entry + /// :param: value + /// :returns: + internal func getClosestStackIndex(#ranges: [ChartRange]?, value: Double) -> Int + { + if ranges == nil + { + return 0 + } + + var stackIndex = 0 + + for range in ranges! + { + if range.contains(value) + { + return stackIndex + } + else + { + stackIndex++ + } + } + + let length = ranges!.count - 1 + + return (value > ranges![length].to) ? length : 0 + } + + /// Same as BarChartHighlighter.getBase() + /// Whatever changed in BarChartHighlighter.getBase() should also be applied here + /// Returns the base x-value to the corresponding x-touch value in pixels. + /// :param: x + /// :returns: + internal func getBase(x: Double) -> Double + { + if let barData = (_chart as? CombinedChartView)?.barData + { + // create an array of the touch-point + var pt = CGPoint() + pt.x = CGFloat(x) + + // take any transformer to determine the x-axis value + (_chart as? CombinedChartView)?.getBarChartTransformer(ChartYAxis.AxisDependency.Left).pixelToValue(&pt) + let xVal = Double(pt.x) + + let setCount = barData.dataSetCount ?? 0 + + // calculate how often the group-space appears + let steps = Int(xVal / (Double(setCount) + Double(barData.groupSpace))) + + let groupSpaceSum = Double(barData.groupSpace) * Double(steps) + + let baseNoSpace = xVal - groupSpaceSum + + return baseNoSpace + } + else + { + return 0.0 + } + } + + /// Same as BarChartHighlighter.getRanges() + /// Whatever changed in BarChartHighlighter.getRanges() should also be applied here + /// Splits up the stack-values of the given bar-entry into Range objects. + /// :param: entry + /// :returns: + internal func getRanges(#entry: BarChartDataEntry) -> [ChartRange]? + { + let values = entry.values + if (values == nil) + { + return nil + } + + var negRemain = -entry.negativeSum + var posRemain: Double = 0.0 + + var ranges = [ChartRange]() + ranges.reserveCapacity(values!.count) + + for (var i = 0, count = values!.count; i < count; i++) + { + let value = values![i] + + if value < 0 + { + ranges.append(ChartRange(from: negRemain, to: negRemain + abs(value))) + negRemain += abs(value) + } + else + { + ranges.append(ChartRange(from: posRemain, to: posRemain+value)) + posRemain += value + } + } + + return ranges + } +} \ No newline at end of file diff --git a/Charts/Classes/Renderers/CombinedChartRenderer.swift b/Charts/Classes/Renderers/CombinedChartRenderer.swift index c6528c3940..66e521e53c 100644 --- a/Charts/Classes/Renderers/CombinedChartRenderer.swift +++ b/Charts/Classes/Renderers/CombinedChartRenderer.swift @@ -209,7 +209,7 @@ public class CombinedChartRenderer: ChartDataRendererBase, public func barChartRenderer(renderer: BarChartRenderer, transformerForAxis which: ChartYAxis.AxisDependency) -> ChartTransformer! { - return _chart.getTransformer(which) + return _chart.getBarChartTransformer(which) } public func barChartRendererMaxVisibleValueCount(renderer: BarChartRenderer) -> Int @@ -234,12 +234,12 @@ public class CombinedChartRenderer: ChartDataRendererBase, public func barChartRendererChartXMax(renderer: BarChartRenderer) -> Double { - return _chart.chartXMax + return _chart._barChartXMax } public func barChartRendererChartXMin(renderer: BarChartRenderer) -> Double { - return _chart.chartXMin + return _chart._barChartXMin } public func barChartIsDrawHighlightArrowEnabled(renderer: BarChartRenderer) -> Bool diff --git a/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj b/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj index 2b13e75ff6..70ee198b21 100644 --- a/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj +++ b/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 13D38A461B708CE1009D4C4D /* GroupedCombinedChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 13D38A451B708CE1009D4C4D /* GroupedCombinedChartViewController.m */; }; 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 */; }; @@ -98,6 +99,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 13D38A441B708CE1009D4C4D /* GroupedCombinedChartViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupedCombinedChartViewController.h; sourceTree = ""; }; + 13D38A451B708CE1009D4C4D /* GroupedCombinedChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupedCombinedChartViewController.m; 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 = ""; }; @@ -310,6 +313,8 @@ 5BDEDC441ABB871E007D3A60 /* CombinedChartViewController.h */, 5BDEDC451ABB871E007D3A60 /* CombinedChartViewController.m */, 5BDEDC461ABB871E007D3A60 /* CombinedChartViewController.xib */, + 13D38A441B708CE1009D4C4D /* GroupedCombinedChartViewController.h */, + 13D38A451B708CE1009D4C4D /* GroupedCombinedChartViewController.m */, 5BEAED2E1ABC18F00013F194 /* CubicLineChartViewController.h */, 5BEAED2F1ABC18F00013F194 /* CubicLineChartViewController.m */, 5BEAED301ABC18F00013F194 /* CubicLineChartViewController.xib */, @@ -490,6 +495,7 @@ 5B57BBB51A9B26AA0036A6CC /* main.m in Sources */, 5BEAED361ABC192F0013F194 /* RadarChartViewController.m in Sources */, 5B9624411B38608C007763E2 /* NegativeStackedBarChartViewController.m in Sources */, + 13D38A461B708CE1009D4C4D /* GroupedCombinedChartViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ChartsDemo/Classes/DemoListViewController.m b/ChartsDemo/Classes/DemoListViewController.m index de3adaa572..5ff01fb400 100644 --- a/ChartsDemo/Classes/DemoListViewController.m +++ b/ChartsDemo/Classes/DemoListViewController.m @@ -17,6 +17,7 @@ #import "BarChartViewController.h" #import "HorizontalBarChartViewController.h" #import "CombinedChartViewController.h" +#import "GroupedCombinedChartViewController.h" #import "PieChartViewController.h" #import "ScatterChartViewController.h" #import "StackedBarChartViewController.h" @@ -71,6 +72,11 @@ - (void)viewDidLoad @"subtitle": @"Demonstrates how to create a combined chart (bar and line in this case).", @"class": CombinedChartViewController.class }, + @{ + @"title": @"Grouped Combined Chart", + @"subtitle": @"Demonstrates how to create a grouped combined chart (bar and line in this case).", + @"class": GroupedCombinedChartViewController.class + }, @{ @"title": @"Pie Chart", @"subtitle": @"A simple demonstration of the pie chart.", diff --git a/ChartsDemo/Classes/Demos/GroupedCombinedChartViewController.h b/ChartsDemo/Classes/Demos/GroupedCombinedChartViewController.h new file mode 100644 index 0000000000..437c118c24 --- /dev/null +++ b/ChartsDemo/Classes/Demos/GroupedCombinedChartViewController.h @@ -0,0 +1,18 @@ +// +// GroupedCombinedChartViewController.h +// ChartsDemo +// +// Created by Xuan on 8/3/15. +// +// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda +// A port of MPAndroidChart for iOS +// Licensed under Apache License 2.0 +// +// https://github.com/danielgindi/ios-charts +// + +#import "CombinedChartViewController.h" + +@interface GroupedCombinedChartViewController : CombinedChartViewController + +@end diff --git a/ChartsDemo/Classes/Demos/GroupedCombinedChartViewController.m b/ChartsDemo/Classes/Demos/GroupedCombinedChartViewController.m new file mode 100644 index 0000000000..a147509b98 --- /dev/null +++ b/ChartsDemo/Classes/Demos/GroupedCombinedChartViewController.m @@ -0,0 +1,112 @@ +// +// GroupedCombinedChartViewController.m +// ChartsDemo +// +// Created by Xuan on 8/3/15. +// +// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda +// A port of MPAndroidChart for iOS +// Licensed under Apache License 2.0 +// +// https://github.com/danielgindi/ios-charts +// + +#import "GroupedCombinedChartViewController.h" +#import "ChartsDemo-Swift.h" + +#define ITEM_COUNT 12 + +@interface GroupedCombinedChartViewController () + +@end + +@implementation GroupedCombinedChartViewController + +// used by lazy nib initializer for subclasses +-(NSString *)nibName { + return @"CombinedChartViewController"; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + +- (LineChartData *)generateLineData +{ + LineChartData *d = [[LineChartData alloc] init]; + + NSArray *colors = @[ChartColorTemplates.vordiplom[0], ChartColorTemplates.vordiplom[1], ChartColorTemplates.vordiplom[2]]; + + NSMutableArray *dataSets = [[NSMutableArray alloc] init]; + + for (int z = 0; z < 3; z++) + { + NSMutableArray *values = [[NSMutableArray alloc] init]; + + for (int i = 0; i < ITEM_COUNT; i++) + { + double val = (double) (arc4random_uniform(25) + i); + [values addObject:[[ChartDataEntry alloc] initWithValue:val xIndex:i]]; + } + + LineChartDataSet *d = [[LineChartDataSet alloc] initWithYVals:values label:[NSString stringWithFormat:@"DataSet %d", z + 1]]; + d.lineWidth = 2.5; + d.circleRadius = 4.0; + + UIColor *color = colors[z % colors.count]; + [d setColor:color]; + [d setCircleColor:color]; + [dataSets addObject:d]; + } + + ((LineChartDataSet *)dataSets[0]).lineDashLengths = @[@5.f, @5.f]; + ((LineChartDataSet *)dataSets[0]).colors = ChartColorTemplates.vordiplom; + ((LineChartDataSet *)dataSets[0]).circleColors = ChartColorTemplates.vordiplom; + [d addDataSet:dataSets[0]]; + [d addDataSet:dataSets[1]]; + [d addDataSet:dataSets[2]]; + + return d; +} + +- (BarChartData *)generateBarData +{ + NSMutableArray *yVals1 = [[NSMutableArray alloc] init]; + NSMutableArray *yVals2 = [[NSMutableArray alloc] init]; + NSMutableArray *yVals3 = [[NSMutableArray alloc] init]; + + for (int i = 0; i < ITEM_COUNT; i++) + { + double val = (double) (arc4random_uniform(15) + 3.0); + [yVals1 addObject:[[BarChartDataEntry alloc] initWithValue:val xIndex:i]]; + + val = (double) (arc4random_uniform(15) + 3.0); + [yVals2 addObject:[[BarChartDataEntry alloc] initWithValue:val xIndex:i]]; + + val = (double) (arc4random_uniform(15) + 3.0); + [yVals3 addObject:[[BarChartDataEntry alloc] initWithValue:val xIndex:i]]; + } + + BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals1 label:@"Company A"]; + [set1 setColor:[UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f]]; + set1.valueFont = [UIFont systemFontOfSize:10.f]; + set1.valueTextColor = [UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f]; + BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithYVals:yVals2 label:@"Company B"]; + [set2 setColor:[UIColor colorWithRed:164/255.f green:228/255.f blue:251/255.f alpha:1.f]]; + set2.valueFont = [UIFont systemFontOfSize:10.f]; + set2.valueTextColor = [UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f]; + BarChartDataSet *set3 = [[BarChartDataSet alloc] initWithYVals:yVals3 label:@"Company C"]; + [set3 setColor:[UIColor colorWithRed:242/255.f green:247/255.f blue:158/255.f alpha:1.f]]; + set3.valueFont = [UIFont systemFontOfSize:10.f]; + set3.valueTextColor = [UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f]; + + BarChartData *d = [[BarChartData alloc] init]; + [d addDataSet:set1]; + [d addDataSet:set2]; + [d addDataSet:set3]; + + return d; +} + +@end