EzDevInfo.com

SwiftCharts

Easy to use and highly customizable charts library for iOS

How do I add legend to SwiftChart library

I am currently using SwiftChart library. I would like to add legend to a multi line chart. I cannot find if there is a way to do this. Can anyone help me here?


Source: (StackOverflow)

Using map to generate a sequence of SwiftChart objects from coordinates

I am trying to iterate over an Array of coordinates to create an object from each coordinate. The coordinates are stored as tuples (x,y,z,label).

private enum University 
{
     case Uni0,Uni1,Uni2, Uni3
}

let models: [(x: CGFloat, y:CGFloat, r:CGFloat, type: University)] = [
        (246.56, 138.98, 1,.Uni0), (218.33, 132.71, 1,.Uni0), (187.79, 127.48, 1, .Uni0), (150.63, 135.5, 1, .Uni0), (185.05, 152.57, 1, .Uni3), (213.15, 155.71, 1, .Uni1), (252.79, 158.85, 1, .Uni2), (315.77, 150.62, 1, .Uni0), (220.55, 149.57, 1, .Uni3)

Line that generates the error

let xValues = models{$0.x}.map{ChartAxisValueInt($0.x,labelSettings: labelSettings)}

ChartAxisValueInt is a class from SwiftCharts. The constructor takes an Int and an instance of ChartLabelSettings.

The error message says that *map cannot be invoked with an argument list of type ((_) -> _ ).

I believe map is appropriate because I want to generate one sequence by appyling a function to each member of another series.

More confusingly, the below example code from SwiftCharts does not generate that error:

let xValues = Array(stride(from: 0, through: 450, by: 50)).map {ChartAxisValueInt($0, labelSettings: labelSettings)}

Source: (StackOverflow)

Advertisements