Skip to content

Adds a much improved LineChart

Pre-release
Pre-release
Compare
Choose a tag to compare
@AppPear AppPear released this 29 Sep 17:26
· 1 commit to feat/new-protocol-and-range since this release

LineChart now supports these new functions:

func setLineWidth(width: CGFloat) - to set line width
func showBackground(_ show: Bool) - to show background below a line
func showChartMarks(_ show: Bool) - to show marks at the points
func setLineStyle(to style: LineStyle) - to set it curved or straight

New elements:

ChartGrid

displays a user defined grid behind chart

func setNumberOfHorizontalLines(_ numberOfLines: Int) - to display horizontal lines
func setNumberOfVerticalLines(_ numberOfLines: Int) - to display vertical lines
func setStoreStyle(_ strokeStyle: StrokeStyle) - to set stroke pattern linewidth etc...
func setColor(_ color: Color) - set color
func showBaseLine(_ show: Bool, with style: StrokeStyle? = nil) - show a line at the base with given style

AxisLabels

displays user defined labels along X or Y or both axises

func setAxisYLabels(_ labels: [String]) - takes and array which will be displayed along Y axis
func setAxisXLabels(_ labels: [String]) - takes and array which will be displayed along X axis

Demo

Displaying a simple line chart with marks and X and Y ranges.

LineChart()
    .setLineWidth(width: 2)
    .showChartMarks(true)
    .showBackground(false)
    .data([2, 4, 5, 1, 3])
    .rangeY(0...10)
    .rangeX(0...10)
    .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.blue, .purple)))

Adding a grid behind the LineChart

ChartGrid {
    LineChart()
        .setLineWidth(width: 2)
        .showChartMarks(true)
        .showBackground(false)
        .data([2, 4, 5, 1, 3])
        .rangeY(0...10)
        .rangeX(0...10)
        .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.blue, .purple)))
}
.setNumberOfHorizontalLines(11)
.setNumberOfVerticalLines(11)
.showBaseLine(true)

Adding labels along X and Y axises

AxisLabels {
    ChartGrid {
        LineChart()
            .setLineWidth(width: 2)
            .showChartMarks(true)
            .showBackground(false)
            .data([2, 4, 5, 1, 3])
            .rangeY(0...10)
            .rangeX(0...10)
            .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.blue, .purple)))
    }
    .setNumberOfHorizontalLines(11)
    .setNumberOfVerticalLines(11)
    .showBaseLine(true)
}
.setAxisYLabels(["0","5","10"])
.setAxisXLabels(["27 Oct", "2 Nov", "9 Nov", "15 Nov", "22 Nov"])