diff --git a/Source/Chart.swift b/Source/Chart.swift index 0a9cc3897..7ded1c708 100644 --- a/Source/Chart.swift +++ b/Source/Chart.swift @@ -144,11 +144,22 @@ open class Chart: UIControl { Enable the lines for the labels on the x-axis */ open var showXLabelsAndGrid: Bool = true + + /** + Show the lines for the labels on the x-axis with dashed pattern + */ + open var showXGridDashed: Bool = true + /** Enable the lines for the labels on the y-axis */ open var showYLabelsAndGrid: Bool = true + /** + Show the lines for the labels on the y-axis with dashed pattern + */ + open var showYGridDashed: Bool = true + /** Height of the area at the bottom of the chart, containing the labels for the x-axis. */ @@ -342,7 +353,7 @@ open class Chart: UIControl { let scaledYValues = scaleValuesOnYAxis( segment.map { $0.y } ) if series.line { - drawLine(scaledXValues, yValues: scaledYValues, seriesIndex: index) + drawLine(scaledXValues, yValues: scaledYValues, seriesIndex: index, width: series.width) } if series.area { drawArea(scaledXValues, yValues: scaledYValues, seriesIndex: index) @@ -461,7 +472,7 @@ open class Chart: UIControl { // MARK: - Drawings - fileprivate func drawLine(_ xValues: [Double], yValues: [Double], seriesIndex: Int) { + fileprivate func drawLine(_ xValues: [Double], yValues: [Double], seriesIndex: Int, width: CGFloat?) { // YValues are "reverted" from top to bottom, so 'above' means <= level let isAboveZeroLine = yValues.max()! <= self.scaleValueOnYAxis(series[seriesIndex].colors.zeroLevel) let path = CGMutablePath() @@ -474,6 +485,7 @@ open class Chart: UIControl { let lineLayer = CAShapeLayer() lineLayer.frame = self.bounds lineLayer.path = path + lineLayer.lineDashPattern = series[seriesIndex].dashed ? [7, 3] : nil if isAboveZeroLine { lineLayer.strokeColor = series[seriesIndex].colors.above.cgColor @@ -481,7 +493,7 @@ open class Chart: UIControl { lineLayer.strokeColor = series[seriesIndex].colors.below.cgColor } lineLayer.fillColor = nil - lineLayer.lineWidth = lineWidth + lineLayer.lineWidth = width ?? lineWidth lineLayer.lineJoin = CAShapeLayerLineJoin.bevel self.layer.addSublayer(lineLayer) @@ -575,6 +587,12 @@ open class Chart: UIControl { if x != 0 && x != drawingWidth { context.move(to: CGPoint(x: x, y: CGFloat(0))) context.addLine(to: CGPoint(x: x, y: bounds.height)) + if labels[i] != 0 && showXGridDashed { + // Vertical grid for 0 is not dashed or when showXGrddDashed is false + context.setLineDash(phase: CGFloat(0), lengths: [CGFloat(5)]) + } else { + context.setLineDash(phase: CGFloat(0), lengths: []) + } context.strokePath() } @@ -649,8 +667,8 @@ open class Chart: UIControl { context.move(to: CGPoint(x: CGFloat(0), y: y)) context.addLine(to: CGPoint(x: self.bounds.width, y: y)) - if labels[i] != 0 { - // Horizontal grid for 0 is not dashed + if labels[i] != 0 && showYGridDashed { + // Horizontal grid for 0 is not dashed or when showYGrodDashed is false context.setLineDash(phase: CGFloat(0), lengths: [CGFloat(5)]) } else { context.setLineDash(phase: CGFloat(0), lengths: []) diff --git a/Source/ChartSeries.swift b/Source/ChartSeries.swift index 46e6207bc..045e91932 100644 --- a/Source/ChartSeries.swift +++ b/Source/ChartSeries.swift @@ -21,6 +21,17 @@ open class ChartSeries { */ open var line: Bool = true + /** + Draws the line in a dashed pattern. + */ + + open var dashed: Bool = false + + /** + The width of the series line. Useful when different line widths are required + */ + open var width: CGFloat? + /** Draws an area below the series line. */