Series: Provide Data

Series use Data protocols to interact with their data sources. This allows you to provide data point parameters from your data sets.

Note that different series types use different data protocols. A Pie series uses the DXPieSeriesData protocol and a Cartesian series uses protocols extending the DXSeriesData protocol. Besides, different cartesian series should use different base protocol descendants, because series visualize different value numbers. Additionally, a Cartesian series should use a data protocol compatible with an X-axis type of a chart; otherwise the chart does not plot the series. Below is a table of protocols' use cases.

Data Protocol Compatible Axis Used in Series Argument/Label Type Values
DXPieSeriesData None Pie series NSString Value
DXQualitativeSeriesData DXQualitativeAxisX Common Cartesian series NSString Value
DXWeightedQualitativeSeriesData DXQualitativeAxisX The Bubble series NSString Value, Weight
DXNumericSeriesData DXNumericAxisX Common Cartesian series double Value
DXWeightedNumericSeriesData DXNumericAxisX The Bubble series double Value, Weight
DXDateTimeSeriesData DXDateTimeAxisX Common Cartesian series NSDate Value
DXWeightedDateTimeSeriesData DXDateTimeAxisX The Bubble series NSDate Value, Weight
DXFinancialSeriesData DXDateTimeAxisX Financial series NSDate Open, High, Low, Close

The following sections explain how to perform typical data providing scenarios.

How to: Provide series data

The code snippet below demonstrates how to implement a DXDateTimeSeriesData protocol:

// Interfaces declaration.
@interface Gdp : NSObject
    @property NSDate *year;
    @property double value;

    +(instancetype) gdpWithYear: (NSDate *)year andValue: (double)value;
@end

@interface GdpData : NSObject <DXDateTimeSeriesData>
    +(instancetype) dataWithArray: (NSArray<Gdp *> *)gdps;
@end

// Interfaces implementation.
@implementation Gdp
    +(instancetype) gdpWithYear:(NSDate *)year andValue: (double)value {
        Gdp *gdp = [[Gdp alloc] init];
        gdp.year = year;
        gdp.value = value;
        return gdp;
    }
@end

@implementation GdpData {
    NSArray<Gdp *> *gdps;
}
    +(instancetype) dataWithArray:(NSArray<Gdp *> *)gdps {
        GdpData *data = [[GdpData alloc] init];
        data->gdps = gdps;
        return data;
    }

    -(int) getDataCount {
        return (int)[gdps count];
    }

    -(NSDate *)getArgumentByIndex: (int)index {
        return [gdps objectAtIndex:index].year;
    }

    -(double) getValueByIndex: (int) index {
        return [gdps objectAtIndex:index].value;
    }
@end

// ...
DXLineSeries *lineSeries = [[DXLineSeries alloc] init];
lineSeries.data = [GdpData dataWithArray:gdps];
[self.chart addSeries:lineSeries];
// ...

Symbols required to specify data.

Symbol Description
DXPieSeries.data
DXSeries.data

How to: Update series data

Your data class should implement the optional delegate property that sends redraw requests to a chart when data changes:

@implementation GdpData {
    NSMutableArray<Gdp *> *gdps;
}

+(instancetype) dataWithArray:(NSMutableArray<Gdp *> *)gdps {
    GdpData *data = [[GdpData alloc] init];
    data->gdps = gdps;
    return data;
}

-(int) getDataCount {
    return (int)[gdps count];
}

-(NSDate *)getArgumentByIndex: (int)index {
    return [gdps objectAtIndex:index].year;
}

-(double) getValueByIndex: (int) index {
    return [gdps objectAtIndex:index].value;
}

// You should notify the delegate about all data changes.
-(void) addGdp: (Gdp *)gdp {
    [gdps addObject:gdp];
    [delegate dataItemDidAdd];
}

@synthesize delegate;
@end
}

// ...
// The chart starts to listen to notifications automatically.
DXLineSeries *lineSeries = [[DXLineSeries alloc] init];
lineSeries.data = [GdpData dataWithArray:gdps];
self.chart.addSeries(line);
// ...

The code above uses the following symbols:

Symbol Details
DXChangeableSeriesData.delegate

The optional property. Returns the delegate of a series data.

DXSeriesDataDelegate

The protocol which a class should adopts to perform actions on data changes.