Skip to content

Usage guide

Francesco Leoni edited this page Apr 10, 2022 · 7 revisions

Usage guide

Chart

let monthsData = [MultiPlotable(name: "jan", values: [33, 43]), [...]]

let data = ChartData(title: "Consumptions",
                     data: monthsData,
                     legendKeys: [Key(key: "F1", color: .Gradient.purpleCyan),
                                  Key(key: "F2", color: .green),
                                  Key(key: "F3", color: .Gradient.sunset)],
                     unitOfMeasure: "scm")

let chart = FLChart(data: data, type: .bar(bar: FLMultipleValuesChartBar.self))

Card

let card = FLCard(chart: chart,
                  style: .rounded)

card.showAverage = false

Bar

To create a custom bar create a class that inherits from ChartBar.

public final class CustomChartBar: UIView, ChartBar {
    
    public var config: ChartConfig?
    public var barConfig: FLBarConfig?

    public func configureViews() { 
        [...]
    }

    public func configureBar(for barHeight: CGFloat, barData: BarData) {
        [...]
    }
}

Highlighted view

To create a custom highlighted view create a class that inherits from HighlightedView.

public final class CustomHighlightedView: UIView, HighlightedView {

    public var dataValue: String?
    
    private let dataValueLabel = UILabel()

    override init(frame: CGRect) {
        super.init(frame: frame)
        [configure views]
    }

    public func update(with value: String?) {
        [...]
    }
}

Line Chart X and Y Segments

let lineChartData = FLChartData([...],
                                legendKeys: [
                                   Key(key: "F1", yThresholds: [40 : .red,
                                                                56 : .blue,
                                                                84 : .green,
                                                                100 : .orange],
                                       data: monthsData),
                                   Key(key: "F2", xColors: [.red,
                                                            .blue,
                                                            .green,
                                                            .orange])],
                                 [...])

Configurations

let barConfig = FLBarConfig(colors: [.red, .blue, .green],
                            radius: .capsule,
                            spacing: 10)
                            
let axesLabelConfig = FLAxisLabelConfig(color: .black,
                                        font: .preferredFont(forTextStyle: .body))
                         
chart.config = ChartConfig(axesLabels: axesLabelConfig)
Clone this wiki locally