SciChart iOS v2.x API > 2D Chart Types > The Line Series Type
The Line Series Type

Line Series are provided by the SCIFastLineRenderableSeries type.

Examples for the Line Series can be found in the SciChart iOS Examples Suite

 

 

To declare a SCIFastLineRenderableSeries use the following code:

 

// Create a SCIChartSurface instance
SCIChartSurface * _sciChartSurface = [[SCIChartSurface alloc]initWithFrame:frame];

// NOTE: You will need to add the SCIChartSurface as a SubView to your View
//
// Declare a new XyDataSeries with XType Float, and YType Float
SCIXyDataSeries * dataSeries = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Float YType:SCIDataType_Float];
// Append some data. SCIGenericStruct converts without boxing of primitives
int dataCount = 20;
for(int i=0; i < dataCount; i++) {
    double time = 10 * i / (double)dataCount;
    double x = time;
    double y = arc4random_uniform(20);
    [dataSeries appendX:SCIGeneric(x) Y:SCIGeneric(y)];
}
// Create a SCIFastLineRenderableSeries and apply DataSeries
SCIFastLineRenderableSeries * lineRenderSeries = [SCIFastLineRenderableSeries new];
lineRenderSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFF279B27 withThickness:1.0];
lineRenderSeries.dataSeries = dataSeries ;
// Note Surface must have an XAxis/YAxis of type SCINumericAxis to match the float,float data
id<SCIAxis2DProtocol> axis = [[SCINumericAxis alloc] init];
[axis setGrowBy: [[SCIDoubleRange alloc]initWithMin:SCIGeneric(0.1) Max:SCIGeneric(0.1)]];
[_sciChartSurface.yAxes add:axis];
axis = [[SCINumericAxis alloc] init];
[axis setGrowBy: [[SCIDoubleRange alloc]initWithMin:SCIGeneric(0.1) Max:SCIGeneric(0.1)]];
[_sciChartSurface.xAxes add:axis];
// Add the Line Series to an existing SciChartSurface
[_sciChartSurface.renderableSeries add:lineRenderSeries];
// Create a SCIChartSurface instance
var sciChartSurface = SCIChartSurface(frame: frame)

// NOTE: You will need to add the SCIChartSurface as a SubView to your View
//

// Declare a new XyDataSeries with XType Float, and YType Float
let dataSeries = SCIXyDataSeries(xType: .float, yType: .float)

// Append some data. SCIGenericStruct converts without boxing of primitives
let dataCount: Int = 20
for i in 0..<dataCount {
    let time = (10.0 * Double(i)) / Double(dataCount)
    let x: Double = time;
    let y: Double = Double(arc4random_uniform(20))
    dataSeries.appendX(SCIGeneric(x), y: SCIGeneric(y))
}

// Create a SCIFastLineRenderableSeries and apply DataSeries
let lineRenderSeries = SCIFastLineRenderableSeries()
lineRenderSeries.strokeStyle = SCISolidPenStyle(colorCode: 0xff279b27, withThickness: 1.0)
lineRenderSeries.dataSeries = dataSeries

// Note Surface must have an XAxis/YAxis of type SCINumericAxis to match the float,float data
let xAxis = SCINumericAxis()
xAxis.growBy = SCIDoubleRange(min: SCIGeneric(0.1), max: SCIGeneric(0.1))
sciChartSurface.yAxes.add(xAxis)

let yAxis = SCINumericAxis()
yAxis.growBy = SCIDoubleRange(min: SCIGeneric(0.1), max: SCIGeneric(0.1))
sciChartSurface.xAxes.add(yAxis)

// Add the Line Series to an existing SciChartSurface
sciChartSurface.renderableSeries.add(lineRenderSeries)
// Create a SCIChartSurface instance
var sciChartSurface = new SCIChartSurface();

// NOTE: You will need to add the SCIChartSurface as a SubView to your View
//

// Declare a new XyDataSeries with XType Float, and YType Float
var dataSeries = new XyDataSeries<float, float>();

// Append some data.
int dataCount = 20;
var random = new Random();
for (int i = 0; i < dataCount; i++)
{
    float x = 10 * i / (float)dataCount;
    float y = random.Next(0, 20);
    dataSeries.Append(x, y);
}

// Create a SCIFastLineRenderableSeries and apply DataSeries
var lineRenderSeries = new SCIFastLineRenderableSeries();
lineRenderSeries.DataSeries = dataSeries;
lineRenderSeries.StrokeStyle = new SCISolidPenStyle(colorCode: 0xFF279B27, thickness: 1.0f);           

// Note Surface must have an XAxis/YAxis of type SCINumericAxis to match the float,float data
var xAxis = new SCINumericAxis { GrowBy = new SCIDoubleRange(0.1, 0.1) };
sciChartSurface.XAxes.Add(xAxis);

var yAxis = new SCINumericAxis { GrowBy = new SCIDoubleRange(0.1, 0.1) };
sciChartSurface.YAxes.Add(yAxis);

// Add the Line Series to an existing SciChartSurface           
sciChartSurface.RenderableSeries.Add(lineRenderSeries);

 

 

Still stuck?

You can check the Online iOS Line Chart Example about using this kind of renderable series.

Also our series of Swift and Xamarin Tutorials here.

 

 

See Also