ChartView

public struct ChartView<Content> : View where Content : View

SwiftUI View’s wrapper for all charts

Usage

let model = ChartModel(chartType: .line,
           data: [[nil, 220, nil, 250, 200, nil, 230],
                  [160, nil, 130, 170, nil, 190, 180]],
           titlesForCategory: [["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"]]
)

 /// default no data view is shown if there is no data in model
 ChartView(model)
     .frame(width: 300, height: 200)

 /// create a chart view with customized no data view
 ChartView(self.info.1[i], noDataView: NoDataView {
     GeometryReader { proxy in
         VStack(alignment: .center) {
             Text("☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹")
             Text("Customized No Data View")
             Text("☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹☹")
         }
         .frame(width: proxy.size.width, height: proxy.size.height)
         .border(Color.primary, width: 1)
     }
 }).frame(width: 300, height: 200)

  • The constructor with a chart model and NoDataView

    Declaration

    Swift

    public init(_ chartModel: ChartModel, noDataView: NoDataView<Content>)

    Parameters

    chartModel

    the chart model

    noDataView

    this view will be shown if chartModel contains no data

  • Declaration

    Swift

    public var body: some View { get }

Available where Content == EmptyView

  • The constructor with a chart model and a default NoDataView is used if there is no data

    Declaration

    Swift

    init(_ chartModel: ChartModel)

    Parameters

    chartModel

    the chart model