ChartModel

public class ChartModel : ObservableObject, Identifiable, NSCopying
extension ChartModel: Equatable
extension ChartModel: CustomStringConvertible

A common data model for all charts. Chart properties can be initialized in init() or changed after init().

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"]]
)

  • An internal data structure to hold a single piece of data or an array of data

    See more

    Declaration

    Swift

    public enum DimensionData<T> : CustomStringConvertible, Equatable where T : Equatable
  • chart type

    Declaration

    Swift

    @Published
    public var chartType: ChartType { get set }
  • series attributes

    Declaration

    Swift

    public var seriesAttributes: [ChartSeriesAttributes] { get set }
  • Provides attributes for the category axis.

    • For stock, clustered column, line, and combo charts this is the X axis.
    • For bar charts this is the Y axis.

    Declaration

    Swift

    @Published
    public var categoryAxis: ChartCategoryAxisAttributes { get set }
  • Provides attributes for the primary numeric axis.

    • For stock, clustered column, line, and combo charts this is the Y axis.
    • For bar charts this is the X axis.

    Declaration

    Swift

    @Published
    public var numericAxis: ChartNumericAxisAttributes { get set }
  • Provides attributes for the secondary numeric axis.

    • For clustered line, area and combo charts this is the secondary Y axis.

    Declaration

    Swift

    @Published
    public var secondaryNumericAxis: ChartNumericAxisAttributes { get set }
  • colors for any category in any series it is optional. this color overwrite the color from seriesAttributes format: [seriesIndex1: [catrgoryIndex1: Color, …, catrgoryIndexN: Color], … , seriesIndexN: [catrgoryIndex1: Color, …, catrgoryIndexM: Color]]

    Declaration

    Swift

    @Published
    public var colorsForCategory: [Int : [Int : Color]] { get set }
  • titles for Axis

    Declaration

    Swift

    @Published
    public var titlesForAxis: [ChartAxisId : String]? { get set }
  • app to provide this to format values for labels of numeric axis

    Declaration

    Swift

    public var numericAxisLabelFormatHandler: NumericAxisLabelFormatHandler?
  • enable or disable user interaction Do not set this property to true if the chart is used as an iOS Widget. Otherwise it will be an empty view

    Declaration

    Swift

    @Published
    public var userInteractionEnabled: Bool { get set }
  • snap to point when dragging a chart

    Declaration

    Swift

    @Published
    public var snapToPoint: Bool { get set }
  • number of gridlines for numeric axis

    Declaration

    Swift

    @PublishedConstrainedValue
    public var numberOfGridlines: Int { get set }
  • the position of X Axis labels, .fixedBottom or .dynamic

    Declaration

    Swift

    @Published
    public var xAxisLabelsPosition: XAxisLabelsPosition { get set }
  • current selected index of stock chart if there are multiple

    Declaration

    Swift

    public var indexOfStockSeries: Int { get set }
  • Undocumented

    Declaration

    Swift

    public var indexesOfColumnSeries: IndexSet { get set }
  • Undocumented

    Declaration

    Swift

    public var indexesOfTotalsCategories: IndexSet { get set }
  • Indicates secondary value axis series indexes for line based charts.

    • The secondary value index works with .line, .area and .combo charts only.
    • Given series indexes will assign the corresponding series to the secondary value axis.

    Declaration

    Swift

    public var indexesOfSecondaryValueAxis: IndexSet { get set }
  • Determines which plot items should be selected for a category.

    • single : Selects a single value in the currently selected series and category indices.
    • all : Selects one value in each series for the selected category index(es).

    Declaration

    Swift

    public var selectionMode: ChartSelectionMode { get set }
  • When false a state is allowed in which no series is selected/active.

    Declaration

    Swift

    @Published
    public var selectionRequired: Bool { get set }
  • Set / get current selection state for the chart view nil means no selection format: [seriesIndex: [categoryIndex]]?, selection mode: single, single selection: [0: [0]] selection mode: single, range selection: [0: [0,1,2,3,4,5,6]] selection mode: all, [0: [0], 1: [0]] multiple selection for donut: [0: [0], 2: [0], 4: [0]]

    Declaration

    Swift

    public var selections: [Int : [Int]]? { get set }
  • a publisher to notify the changes of chart selections usage: var cancellableSet: Set = []

    model.selectionDidChangePublisher .subscribe(on: RunLoop.main) .sink(receiveValue: { (selections) in if let selections = selections { for (seriesIndex, catIndices) in selections { print(“Selected series: (seriesIndex), selected categories: (catIndices)”) } } else { print(“No selections”) } }) .store(in: &cancellableSet)

    Declaration

    Swift

    public private(set) lazy var selectionDidChangePublisher: AnyPublisher<[Int : [Int]]?, Never> { get set }
  • the center position of a chart in relative coordinate system, both x and y are range from 0 to 1

    Declaration

    Swift

    @Published
    public var centerPosition: CGPoint? { get set }
  • X direction scale factor, scale is not allowed to be less than 1.0

    Declaration

    Swift

    public var scaleX: CGFloat { get set }
  • Y direction scale factor, scale is not allowed to be less than 1.0

    Declaration

    Swift

    public var scaleY: CGFloat { get set }
  • enable/disable X direction scale by gesture

    Declaration

    Swift

    @Published
    public var scaleXEnabled: Bool { get set }
  • enable/disable Y direction scale by gesture

    Declaration

    Swift

    @Published
    public var scaleYEnabled: Bool { get set }
  • when it is true there is a minimum width of a column (20 pts)

    Declaration

    Swift

    @Published
    public var readableScaleEnabled: Bool { get set }
  • enable/disable selection gestures

    Declaration

    Swift

    @Published
    public var selectionEnabled: Bool { get set }
  • id

    Declaration

    Swift

    public let id: UUID
  • Initializes and returns a newly allocated ChartModel for most of chart types. The data should contain only two dimension array of double values.

    Declaration

    Swift

    public convenience init(chartType: ChartType,
                            data: [[Double?]],
                            titlesForCategory: [[String?]]? = nil,
                            colorsForCategory: [Int: [Int: Color]]? = nil,
                            titlesForAxis: [ChartAxisId: String]? = nil,
                            labelsForDimension: [[String?]]? = nil,
                            numberOfGridlines: Int = 3,
                            selectionRequired: Bool = false,
                            selectionMode: ChartSelectionMode = .single,
                            selections: [Int: [Int]]? = nil,
                            userInteractionEnabled: Bool = false,
                            selectionEnabled: Bool = false,
                            centerPosition: CGPoint? = nil,
                            scaleX: CGFloat = 1.0,
                            scaleY: CGFloat = 1.0,
                            scaleXEnabled: Bool = false,
                            scaleYEnabled: Bool = false,
                            readableScaleEnabled: Bool = true,
                            snapToPoint: Bool = false,
                            seriesAttributes: [ChartSeriesAttributes]? = nil,
                            categoryAxis: ChartCategoryAxisAttributes? = nil,
                            numericAxis: ChartNumericAxisAttributes? = nil,
                            secondaryNumericAxis: ChartNumericAxisAttributes? = nil,
                            xAxisLabelsPosition: XAxisLabelsPosition = .fixedBottom,
                            indexOfStockSeries: Int = 0,
                            indexesOfSecondaryValueAxis: [Int]? = nil,
                            indexesOfColumnSeries: [Int]? = nil,
                            indexesOfTotalsCategories: [Int]? = nil,
                            numericAxisLabelFormatHandler: NumericAxisLabelFormatHandler? = nil)

    Parameters

    chartType

    chart type

    data

    two dimension array of double values.

    titlesForCategory

    labels for x axis

    colorsForCategory

    colors for any category in any series. it is optional. this color overwrite the color from seriesAttributes.

    titlesForAxis

    titles for category and numeric Axis

    labelsForDimension

    labels for dimension data

    numberOfGridlines

    number of gridlines for numeric axis

    selectionMode

    determines which plot items should be selected for a category. It could be single, all, multiple

    selections

    preselected categories or series for the chart view. For example it could be [0: [0,1,2,3,4,5,6]], [0: [0], 1: [0]]

    userInteractionEnabled

    enable or disable user interaction

    selectionEnabled

    enable or disable user interaction for selection including single tap, double tap and two fingers long pressed

    snapToPoint

    snap to point when dragging a chart

    seriesAttributes

    series attributes

    categoryAxis

    attributes for the category axis.

    numericAxis

    attributes for the primary numeric axis.

    secondaryNumericAxis

    attributes for the secondary numeric axis.

    xAxisLabelsPosition

    the position of X Axis labels, .fixedBottom or .dynamic

    indexOfStockSeries

    current selected index of stock chart if there are multiple

    indexesOfSecondaryValueAxis

    indicates secondary value axis series indexes for line based charts (.line, .area and .combo).

    indexesOfColumnSeries

    indicates indexes of column series for combo chart.

    indexesOfTotalsCategories

    indicates total indexes for waterfall chart.

    numericAxisLabelFormatHandler

    format values for labels of numeric axis

  • Initializes and returns a newly allocated ChartModel for bubble or stock charts. The data should only contain 3 dimension array of double values.

    Declaration

    Swift

    public convenience init(chartType: ChartType,
                            data3d: [[[Double?]]],
                            titlesForCategory: [[String?]]? = nil,
                            colorsForCategory: [Int: [Int: Color]]? = nil,
                            titlesForAxis: [ChartAxisId: String]? = nil,
                            labelsForDimension: [[[String?]]]? = nil,
                            numberOfGridlines: Int = 3,
                            selectionMode: ChartSelectionMode = .single,
                            selections: [Int: [Int]]? = nil,
                            userInteractionEnabled: Bool = false,
                            selectionEnabled: Bool = false,
                            centerPosition: CGPoint? = nil,
                            scaleX: CGFloat = 1.0,
                            scaleY: CGFloat = 1.0,
                            scaleXEnabled: Bool = false,
                            scaleYEnabled: Bool = false,
                            readableScaleEnabled: Bool = true,
                            snapToPoint: Bool = false,
                            seriesAttributes: [ChartSeriesAttributes]? = nil,
                            categoryAxis: ChartCategoryAxisAttributes? = nil,
                            numericAxis: ChartNumericAxisAttributes? = nil,
                            secondaryNumericAxis: ChartNumericAxisAttributes? = nil,
                            xAxisLabelsPosition: XAxisLabelsPosition = .fixedBottom,
                            indexOfStockSeries: Int = 0,
                            indexesOfSecondaryValueAxis: [Int]? = nil,
                            indexesOfColumnSeries: [Int]? = nil,
                            indexesOfTotalsCategories: [Int]? = nil,
                            numericAxisLabelFormatHandler: NumericAxisLabelFormatHandler? = nil)

    Parameters

    chartType

    chart type

    data3d

    three dimension array of double values.

    titlesForCategory

    labels for x axis

    colorsForCategory

    colors for any category in any series. it is optional. this color overwrite the color from seriesAttributes.

    titlesForAxis

    titles for category and numeric Axis

    labelsForDimension

    labels for dimension data

    numberOfGridlines

    number of gridlines for numeric axis

    selectionMode

    determines which plot items should be selected for a category. It could be single, all, multiple

    selections

    preselected categories or series for the chart view. For example it could be [0: [0,1,2,3,4,5,6]], [0: [0], 1: [0]]

    userInteractionEnabled

    enable or disable user interaction

    selectionEnabled

    enable or disable user interaction for selection including single tap, double tap and two fingers long pressed

    snapToPoint

    snap to point when dragging a chart

    seriesAttributes

    series attributes

    categoryAxis

    attributes for the category axis.

    numericAxis

    attributes for the primary numeric axis.

    secondaryNumericAxis

    attributes for the secondary numeric axis.

    xAxisLabelsPosition

    the position of X Axis labels, .fixedBottom or .dynamic

    indexOfStockSeries

    current selected index of stock chart if there are multiple

    indexesOfSecondaryValueAxis

    indicates secondary value axis series indexes for line based charts (.line, .area and .combo).

    indexesOfColumnSeries

    indicates indexes of column series for combo chart.

    indexesOfTotalsCategories

    indicates total indexes for waterfall chart.

    numericAxisLabelFormatHandler

    format values for labels of numeric axis

  • Undocumented

    Declaration

    Swift

    public func copy(with zone: NSZone? = nil) -> Any
  • number of series in the chart model

    Declaration

    Swift

    public func numOfSeries() -> Int
  • number of categories for charts except stock, bubble and scatter

    Declaration

    Swift

    public func numOfCategories() -> Int
  • number of categories in the series

    Declaration

    Swift

    public func numOfCategories(in seriesId: Int) -> Int
  • Returns plot item value for given indexes of series, category and dimension.

    Declaration

    Swift

    public func plotItemValue(at series: Int, category: Int, dimension: Int) -> Double?
  • Undocumented

    Declaration

    Swift

    public func categoryTitles(at series: Int, category: Int) -> String?
  • Declaration

    Swift

    public static func == (lhs: ChartModel, rhs: ChartModel) -> Bool
  • Declaration

    Swift

    public var description: String { get }