Last active
August 29, 2015 14:24
-
-
Save erica/253cfaaf6a09f977baa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func BarChart(numbers : [Int]) -> NSImage { | |
var endPoint = "http://chart.apis.google.com/chart?" | |
endPoint += "cht=bhs" // bar chart | |
endPoint += "&" + "chd=t:" + ",".join(numbers.map({String($0)})) // numbers | |
endPoint += "&" + "chs=480x320" // size | |
endPoint += "&" + "chds=a" // automatic data scaling | |
endPoint += "&" + "chxt=x,y" // labels | |
do { | |
guard let url = NSURL(string:endPoint) else {return NSImage()} | |
let data = try NSURLConnection.sendSynchronousRequest( | |
NSURLRequest(URL: url), returningResponse: nil) | |
guard let image = NSImage(data: data) else { | |
print(NSString(data:data, encoding: NSUTF8StringEncoding)) | |
return NSImage() | |
} | |
return image | |
} catch {print(error)} | |
return NSImage() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment