diff --git a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift index c2915abb84..7ad28bf691 100644 --- a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift +++ b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift @@ -189,6 +189,8 @@ open class ChartBaseDataSet: NSObject, ChartDataSetProtocol, NSCopying /// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. open var colors = [NSUIColor]() + open var cornerRadius: Double = 0 + /// List representing all colors that are used for drawing the actual values for this DataSet open var valueColors = [NSUIColor]() diff --git a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift index 9cf80d3368..82e0ddeac6 100644 --- a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift +++ b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift @@ -179,6 +179,8 @@ public protocol ChartDataSetProtocol /// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. var colors: [NSUIColor] { get } + var cornerRadius: Double { get } + /// - Returns: The color at the given index of the DataSet's color array. /// This prevents out-of-bounds by performing a modulus on the color index, so colours will repeat themselves. func color(atIndex: Int) -> NSUIColor diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 2aa69a828f..acb1f11222 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -379,7 +379,13 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer context.setFillColor(dataSet.color(atIndex: j).cgColor) } - context.fill(barRect) + if dataSet.cornerRadius > 0 { + let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:dataSet.cornerRadius,height:dataSet.cornerRadius)); + context.addPath(bezierPath.cgPath) + context.drawPath(using: .fill) + } else { + context.fill(barRect) + } if drawBorder { @@ -744,7 +750,13 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer setHighlightDrawPos(highlight: high, barRect: barRect) - context.fill(barRect) + if set.cornerRadius > 0 { + let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:set.cornerRadius,height:set.cornerRadius)); + context.addPath(bezierPath.cgPath) + context.drawPath(using: .fill) + } else { + context.fill(barRect) + } } } }