swift - Cannot invoke initializer for type CGFloat with an argument list of type 'String' -


i making bar chart jbchart. change chartdata string. please me it.

here's chartdata code: var chartdata = [1, 2, 3]

then want change string uilabel other view controller.

var chartdata = [score1, score2, score3] 

but error (cannot invoke initializer type cgfloat argument list of type 'string')in code:

    public func barchartview(_ barchartview: jbbarchartview!, heightforbarviewat index: uint) -> cgfloat {         return cgfloat(chartdata[int(index)])     } 

the error saying cgfloat doesn't have initializer accept string argument. can use wrapped around first convert string float , convert float cgfloat.

public func barchartview(_ barchartview: jbbarchartview!, heightforbarviewat index: uint) -> cgfloat {      if let value = float(chartdata[int(index)]) {         return cgfloat(value)     }     return 0 } 

note: sure string have number value otherwise return 0 height.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -