diff --git a/Charts/Classes/Data/CandleChartDataSet.swift b/Charts/Classes/Data/CandleChartDataSet.swift index ad1c2b11df..b285bfc64d 100644 --- a/Charts/Classes/Data/CandleChartDataSet.swift +++ b/Charts/Classes/Data/CandleChartDataSet.swift @@ -28,6 +28,9 @@ public class CandleChartDataSet: BarLineScatterCandleChartDataSet /// the color of the shadow line public var shadowColor: UIColor? + /// use candle color for the shadow + public var makeShadowSameColorAsCandle = false + /// color for open <= close public var decreasingColor: UIColor? diff --git a/Charts/Classes/Data/ChartData.swift b/Charts/Classes/Data/ChartData.swift index 9d8ac45636..c3bce20015 100644 --- a/Charts/Classes/Data/ChartData.swift +++ b/Charts/Classes/Data/ChartData.swift @@ -687,6 +687,10 @@ public class ChartData: NSObject var entry = _dataSets[dataSetIndex].entryForXIndex(xIndex) + if (entry?.xIndex != xIndex) { + return false + } + return removeEntry(entry, dataSetIndex: dataSetIndex) } diff --git a/Charts/Classes/Renderers/CandleStickChartRenderer.swift b/Charts/Classes/Renderers/CandleStickChartRenderer.swift index 7747fa8c9b..957a99f9a5 100644 --- a/Charts/Classes/Renderers/CandleStickChartRenderer.swift +++ b/Charts/Classes/Renderers/CandleStickChartRenderer.swift @@ -98,7 +98,20 @@ public class CandleStickChartRenderer: ChartDataRendererBase // draw the shadow - CGContextSetStrokeColorWithColor(context, (dataSet.shadowColor ?? dataSet.colorAt(j)).CGColor) + var shadowColor = dataSet.shadowColor ?? dataSet.colorAt(j) + if (dataSet.makeShadowSameColorAsCandle) + { + if (e.open > e.close) + { + shadowColor = dataSet.decreasingColor ?? dataSet.colorAt(j) + } + else if (e.open < e.close) + { + shadowColor = dataSet.increasingColor ?? dataSet.colorAt(j) + } + } + + CGContextSetStrokeColorWithColor(context, shadowColor.CGColor); CGContextStrokeLineSegments(context, _shadowPoints, 2) @@ -112,7 +125,12 @@ public class CandleStickChartRenderer: ChartDataRendererBase trans.rectValueToPixel(&_bodyRect) // draw body differently for increasing and decreasing entry - if (e.open >= e.close) + + if (e.open == e.close) { + CGContextSetStrokeColorWithColor(context, shadowColor.CGColor) + CGContextStrokeRect(context, _bodyRect) + } + else if (e.open > e.close) { var color = dataSet.decreasingColor ?? dataSet.colorAt(j)