Data Source Helper
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic provides an introductory overview of data source helper in the IGSparklineView™ and using a code example demonstrates how to configure it.

In this topic


Introduction

Data source helper summary

Using the IGSparklineViewDataSourceHelper eliminates the need to implement any of the required protocol methods found in the IGSparklineViewDataSource class. Thus, allowing you to simplify the wiring up of data to the IGSparklineView control by using the data source helper specialized for this control.

The IGSparklineViewDataSourceHelper is extremely flexible in how the values and labels can be loaded. These initialization methods for directly loading your data arrays or with an array custom NSObjects are supported.

  • initWithValues:
  • initWithValues:labels:
  • initWithData:valuePath:
  • initWithData:valuePath:labelPath:

Additionally, the IGSparklineViewDataSourceHelper can be initialized with the generic init method, and the properties; data, values, labels, valuePath, labelPath, depending on the use case, can be manually set.


Data Source Helper – Code Example

Description

The code below demonstrates loading an NSMutableArray of NSObjects that contain data value and label properties. First, initialize the IGSparklineViewDataSourceHelper with the data and values and then assign the data source helper instance to the dataSource property found on the IGSparklineView.

Prerequisites

This code example requires the inclusion of the Chart framework, detail about how to add this framework can be found in the Adding the Chart Framework File topic.

Code

In Objective-C:

@interface SimpleData : NSObject
@property (nonatomic, assign) double value;
@property (nonatomic, retain) NSString *label;
@end
@implementation SimpleData
@end
//...
NSMutableArray *data = [[NSMutableArray alloc]init];
// ...Add NSObjects such as the SimpleData object above to the array, the NSObject in this example must contain the property named “value” and a property named “label”.
IGSparklineViewDataSourceHelper *sparklineDataSourceHelper = [[IGSparklineViewDataSourceHelper alloc]initWithData:data valuePath:@"value" labelPath:@"label"];
//...
sparklineView.dataSource = sparklineDataSourceHelper;

In C#:

public class SimpleData : NSObject
{
    [Export("Value")]
    public double value { get; set;}
    [Export("Label")]
    public string label { get; set; }
    public SimpleData (double data_value, string data_label)
    {
        value = data_value;
        label = data_label;
    }
}
//...
List<DataObject> data = new List<DataObject>;
// ...Add custom data NSObjects such as the SimpleData object above to the list collection, the NSObject in this example must contain the property named “value” and a property named “label”.
IGSparklineViewDataSourceHelper sparklineDataSourceHelper = new IGSparklineViewDataSourceHelper (data.ToArray (), "value", "label");
//...
sparklineView.DataSource = sparklineDataSourceHelper;

Related Content

Topics

The following topic provides additional information related to this topic.

Topic

Purpose

The topics in this group cover enabling, configuring, and using the IGSparklineView control’s supported features.