View

extension View
  • Adds an independent line on top of FilledLineChart.

    Allows for a hard line over the data point with a semi opaque fill.

    Requires

    Chart Data to conform to CTLineChartDataProtocol.
    • LineChartData

    Available for:

    • Filled Line Chart

    Unavailable for:

    • Line Chart
    • Multi Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart
    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func filledTopLine<T: LineChartData>(
        chartData: T,
        lineColour: ColourStyle = ColourStyle(),
        strokeStyle: StrokeStyle = StrokeStyle()
    ) -> some View

    Parameters

    chartData

    Chart data model.

    lineColour

    Line Colour

    strokeStyle

    Stroke Style

    Return Value

    A new view containing the chart with point markers.

  • Lays out markers over each of the data point.

    The style of the markers is set in the PointStyle data model as parameter in the Chart Data.

    Requires

    Chart Data to conform to CTLineChartDataProtocol.
    • LineChartData
    • MultiLineChartData

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart

    Unavailable for:

    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart
    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func pointMarkers<T>(chartData: T) -> some View where T : CTLineChartDataProtocol, T : GetDataProtocol

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with point markers.

  • Displays the metadata about the chart.

    Adds a view above the chart that displays the title and subtitle. If infoBoxPlacement is set to .header then the datapoint info will be displayed here as well.

    Declaration

    Swift

    public func headerBox<T>(chartData: T) -> some View where T : CTChartData

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with a view above to display metadata.

  • Displays legends under the chart.

    Declaration

    Swift

    public func legends<T:CTChartData>(
        chartData: T,
        columns: [GridItem] = [GridItem(.flexible())],
        iconWidth: CGFloat = 40,
        font: Font = .caption,
        textColor: Color = Color.primary,
        topPadding: CGFloat = 18
    ) -> some View

    Parameters

    chartData

    Chart data model.

    columns

    How to layout the legends.

    textColor

    Colour of the text.

    Return Value

    A new view containing the chart with chart legends under.

  • Adds touch interaction with the chart.

    Adds an overlay to detect touch and display the relivent information from the nearest data point.

    Requires

    If ChartStyle –> infoBoxPlacement is set to .header then .headerBox is required.

    If ChartStyle –> infoBoxPlacement is set to .infoBox then .infoBox is required.

    If ChartStyle –> infoBoxPlacement is set to .floating then .floatingInfoBox is required.

    Attention

    Unavailable in tvOS

    Declaration

    Swift

    public func touchOverlay<T: CTChartData>(
        chartData: T,
        specifier: String = "%.0f",
        formatter: NumberFormatter? = nil,
        unit: TouchUnit = .none,
        minDistance: CGFloat = 0
    ) -> some View

    Parameters

    chartData

    Chart data model.

    specifier

    Decimal precision for labels.

    unit

    Unit to put before or after the value.

    minDistance

    The distance that the touch event needs to travel to register.

    Return Value

    A new view containing the chart with a touch overlay.

  • Adds touch interaction with the chart.

    Attention

    Unavailable in tvOS
  • Undocumented

    Declaration

    Swift

    public func disableAnimation<ChartData>(chartData: ChartData, _ value: Bool = true) -> some View where ChartData : CTChartData

View Extension

  • Adds an seperate line that is over-layed on top of a other chart.

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Declaration

    Swift

    public func extraLine<T: CTLineBarChartDataProtocol>(
        chartData: T,
        legendTitle: String,
        datapoints: @escaping () -> ([ExtraLineDataPoint]),
        style: @escaping () -> (ExtraLineStyle)
    ) -> some View

    Parameters

    chartData

    Data that conforms to CTLineBarChartDataProtocol.

    legendTitle

    Title of the extra line to display in the legends.

    datapoints

    Data point to create the line.

    style

    Styling data for the line.

    Return Value

    The chart with an extra line stacked on top.

  • Adds an seperate line that is over-layed on top of a other chart.

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Declaration

    Swift

    public func extraLine<T: CTLineBarChartDataProtocol>(
        chartData: T,
        legendTitle: String,
        datapoints: @escaping @autoclosure () -> ([ExtraLineDataPoint]),
        style: @escaping @autoclosure () -> (ExtraLineStyle)
    ) -> some View

    Parameters

    chartData

    Data that conforms to CTLineBarChartDataProtocol.

    legendTitle

    Title of the extra line to display in the legends.

    datapoints

    Data point to create the line.

    style

    Styling data for the line.

    Return Value

    The chart with an extra line stacked on top.

  • Adds a second set of Y axis labels.

    Declaration

    Swift

    public func extraYAxisLabels<T: CTLineBarChartDataProtocol>(
        chartData: T,
        specifier: String = "%.0f",
        colourIndicator: AxisColour = .none
    ) -> some View

    Parameters

    chartData

    Data that conforms to CTLineBarChartDataProtocol.

    specifier

    Decimal precision for labels.

    colourIndicator

    Second Y Axis style.

    Return Value

    A View with second set of Y axis labels.

  • A view that displays information from TouchOverlay.

    Places the info box on top of the chart.

    Declaration

    Swift

    public func floatingInfoBox<T>(chartData: T) -> some View where T : CTLineBarChartDataProtocol

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with a view to display touch overlay information.

  • A view that displays information from TouchOverlay.

    Places the info box on top of the chart.

    Declaration

    Swift

    public func floatingInfoBox<T>(chartData: T) -> some View where T : CTLineBarChartDataProtocol, T : isHorizontal

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with a view to display touch overlay information.

Horizontal

  • A view that displays information from TouchOverlay.

    Declaration

    Swift

    public func infoBox<T: CTLineBarChartDataProtocol>(
        chartData: T,
        height: CGFloat = 70
    ) -> some View

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with a view to display touch overlay information.

  • A view that displays information from TouchOverlay.

    Declaration

    Swift

    public func infoBox<T: CTLineBarChartDataProtocol & isHorizontal>(
        chartData: T,
        width: CGFloat = 70
    ) -> some View

    Parameters

    chartData

    Chart data model.

    width

    Width of the view.

    Return Value

    A new view containing the chart with a view to display touch overlay information.

  • Draws a line across the chart to show the the trend in the data.

    Declaration

    Swift

    public func linearTrendLine<T: CTLineBarChartDataProtocol & GetDataProtocol>(
        chartData: T,
        firstValue: Double,
        lastValue: Double,
        lineColour: ColourStyle = ColourStyle(),
        strokeStyle: StrokeStyle = StrokeStyle()
    ) -> some View

    Parameters

    chartData

    Chart data model.

    firstValue

    The value of the leading data point.

    lastValue

    The value of the trailnig data point.

    lineColour

    Line Colour.

    strokeStyle

    Stroke Style.

    Return Value

    A new view containing the chart with a trend line.

  • Adds vertical lines along the X axis.

    The style is set in ChartData –> ChartStyle –> xAxisGridStyle

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart

    Unavailable for:

    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func xAxisGrid<T>(chartData: T) -> some View where T : CTLineBarChartDataProtocol

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with vertical lines under it.

  • Labels for the X axis.

    The labels can either come from ChartData –> xAxisLabels or ChartData –> DataSets –> DataPoints

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart

    Unavailable for:

    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func xAxisLabels<T>(chartData: T) -> some View where T : CTLineBarChartDataProtocol

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with labels marking the x axis.

Extension

  • Vertical line marking a custom value.

    Shows a marker line at a specified value.

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart

    Unavailable for:

    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func xAxisPOI<T:CTLineBarChartDataProtocol & GetDataProtocol & PointOfInterestProtocol>(
        chartData: T,
        markerName: String,
        markerValue: Int,
        dataPointCount: Int,
        lineColour: Color = Color(.blue),
        labelBorderColor: Color? = nil,
        strokeStyle: StrokeStyle = StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round, miterLimit: 10, dash: [CGFloat](), dashPhase: 0),
        labelPosition: DisplayValue = .center(specifier: "%.0f"),
        labelFont: Font = .caption,
        labelColour: Color = Color.primary,
        labelBackground: Color = Color.systemsBackground,
        customLabelShape: CustomLabelShape? = nil,
        padding: CGFloat? = nil,
        addToLegends: Bool = true
    ) -> some View

    Parameters

    chartData

    Chart data model.

    markerName

    Title of marker, for the legend.

    markerValue

    Value to mark.

    dataPointCount

    Total number of data points in data set.

    labelPosition

    Option to display the markers’ value inline with the marker.

    labelFont

    Font for the label.

    labelColour

    Colour of the Text.

    labelBackground

    Colour of the background.

    lineColour

    Line Colour.

    labelBorderColor

    Custom Color for the label border, if not provided lineColor will be used.

    strokeStyle

    Style of Stroke.

    customLabelShape

    Custom Shape for POI Label.

    padding

    Custom Padding between Shape and Text.

    addToLegends

    Whether or not to add this to the legends.

    Return Value

    A new view containing the chart with a marker line at a specified value.

  • Adds horizontal lines along the X axis.

    The style is set in ChartData –> LineChartStyle –> yAxisGridStyle

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart

    Unavailable for:

    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func yAxisGrid<T>(chartData: T) -> some View where T : CTLineBarChartDataProtocol

    Parameters

    chartData

    Chart data model.

    Return Value

    A new view containing the chart with horizontal lines under it.

  • Automatically generated labels for the Y axis.

    Controls are in ChartData –> ChartStyle

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart

    Unavailable for:

    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func yAxisLabels<T: CTLineBarChartDataProtocol>(
        chartData: T,
        specifier: String = "%.0f",
        formatter: NumberFormatter? = nil,
        colourIndicator: AxisColour = .none
    ) -> some View

    Parameters

    chartData

    Data that conforms to CTLineBarChartDataProtocol

    specifier

    Decimal precision specifier

    Return Value

    HStack of labels

Extensions

  • Horizontal line marking a custom value.

    Shows a marker line at a specified value.

    Example

    .yAxisPOI(chartData: data,
                 markerName: "Marker",
                 markerValue: 110,
                 labelPosition: .center(specifier: "%.0f"),
                 labelColour: Color.white,
                 labelBackground: Color.red,
                 lineColour: .blue,
                 strokeStyle: StrokeStyle(lineWidth: 2,
                                          lineCap: .round,
                                          lineJoin: .round,
                                          miterLimit: 10,
                                          dash: [8],
                                          dashPhase: 0))
    

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart

    Unavailable for:

    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func yAxisPOI<T:CTLineBarChartDataProtocol & GetDataProtocol & PointOfInterestProtocol>(
        chartData: T,
        markerName: String,
        markerValue: Double,
        labelPosition: DisplayValue = .center(specifier: "%.0f"),
        labelFont: Font = .caption,
        labelColour: Color = Color.primary,
        labelBackground: Color = Color.systemsBackground,
        lineColour: Color = Color(.blue),
        labelBorderColor: Color? = nil,
        strokeStyle: StrokeStyle = StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round, miterLimit: 10, dash: [CGFloat](), dashPhase: 0),
        customLabelShape: CustomLabelShape? = nil,
        padding: CGFloat? = nil,
        addToLegends: Bool = true
    ) -> some View

    Parameters

    chartData

    Chart data model.

    markerName

    Title of marker, for the legend.

    markerValue

    Value to mark

    labelPosition

    Option to display the markers’ value inline with the marker.

    labelFont

    Font for the label.

    labelColour

    Colour of the Text.

    labelBackground

    Colour of the background.

    lineColour

    Line Colour.

    labelBorderColor

    Custom Color for the label border, if not provided lineColor will be used.

    strokeStyle

    Style of Stroke.

    customLabelShape

    Custom Shape for POI Label.

    padding

    Custom Padding between Shape and Text.

    addToLegends

    Whether or not to add this to the legends.

    Return Value

    A new view containing the chart with a marker line at a specified value.

  • Horizontal line marking the average.

    Shows a marker line at the average of all the data points within the relevant data set(s).

    Example

    .averageLine(chartData: data,
                 markerName: "Average",
                 labelPosition: .center(specifier: "%.0f"),
                 labelColour: Color.white,
                 labelBackground: Color.red,
                 lineColour: .primary,
                 strokeStyle: StrokeStyle(lineWidth: 2,
                                          lineCap: .round,
                                          lineJoin: .round,
                                          miterLimit: 10,
                                          dash: [8],
                                          dashPhase: 0))
    

    Requires

    Chart Data to conform to CTLineBarChartDataProtocol.

    Available for:

    • Line Chart
    • Multi Line Chart
    • Filled Line Chart
    • Ranged Line Chart
    • Bar Chart
    • Grouped Bar Chart
    • Stacked Bar Chart
    • Ranged Bar Chart

    Unavailable for:

    • Pie Chart
    • Doughnut Chart

    Declaration

    Swift

    public func averageLine<T:CTLineBarChartDataProtocol & GetDataProtocol & PointOfInterestProtocol>(
        chartData: T,
        markerName: String = "Average",
        labelPosition: DisplayValue = .yAxis(specifier: "%.0f"),
        labelFont: Font = .caption,
        labelColour: Color = Color.primary,
        labelBackground: Color = Color.systemsBackground,
        lineColour: Color = Color.primary,
        labelBorderColor: Color? = nil,
        strokeStyle: StrokeStyle = StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round, miterLimit: 10, dash: [CGFloat](), dashPhase: 0),
        customLabelShape: CustomLabelShape? = nil,
        padding: CGFloat? = nil,
        addToLegends: Bool = true
    ) -> some View

    Parameters

    chartData

    Chart data model.

    markerName

    Title of marker, for the legend.

    labelPosition

    Option to display the markers’ value inline with the marker.

    labelFont

    Font for the label.

    labelColour

    Colour of the Text.

    labelBackground

    Colour of the background.

    lineColour

    Line Colour.

    labelBorderColor

    Custom Color for the label border, if not provided lineColor will be used.

    strokeStyle

    Style of Stroke.

    customLabelShape

    Custom Shape for POI Label.

    padding

    Custom Padding between Shape and Text.

    addToLegends

    Whether or not to add this to the legends.

    Return Value

    A new view containing the chart with a marker line at the average.