嗨,我想使用highcharter()为美国的每个州(大型数据集)创建一个向下钻取栏。我的数据是:
enum ImageResult {
case success(UIImage)
case failure(Error)
}
enum PhotoError: Error {
case imageCreationError
}
enum PhotoResult {
case success([Photo])
case failure(Error)
}
class PhotoStore {
private let session: URLSession = {
return URLSession(configuration: .default)
}()
let imageStore = ImageStore()
func fetchInterestingPhoto(completion: @escaping (PhotoResult) -> Void) {
let url = FlickerAPI.interestingPhotoURL
let request = URLRequest(url: url)
let task = session.dataTask(with: request) { (data, response, error) in
let result = self.processPhotosRequest(data: data, error: error)
OperationQueue.main.addOperation {
completion(result)
}
}
task.resume()
}
private func processPhotosRequest(data: Data?, error: Error?) -> PhotoResult {
guard let jsonData = data else { return .failure(error!) }
return FlickerAPI.photos(fromJSON: jsonData)
}
func fetchImage(for photo: Photo, completion: @escaping (ImageResult) -> Void) {
let photoKey = photo.photoID
if let image = imageStore.image(forKey: photoKey) {
OperationQueue.main.addOperation {
completion(.success(image))
}
return
}
let photoURL = photo.remoteURL
let request = URLRequest(url: photoURL)
let task = session.dataTask(with: request) { (data, response, error) in
let result = self.processImageRequest(data: data, error: error)
if case let .success(image) = result {
self.imageStore.setImage(image, forKey: photoKey)
}
OperationQueue.main.addOperation {
completion(result)
}
}
task.resume()
}
private func processImageRequest(data: Data?, error: Error?) -> ImageResult {
guard
let imageData = data,
let image = UIImage(data: imageData)
else {
// Couldn't create an image
if data == nil {
return .failure(error!)
} else {
return .failure(PhotoError.imageCreationError)
}
}
return .success(image)
}
}
条形图的高度是每个State<-c("ALABAMA","ALABAMA","ALASKA","ALASKA")
County<-c("AUTAUGA","BALDWIN","ANCHORAGE","BETHEL")
Num<-c(5,6,7,8)
d<-data.frame(State,County, Num)
或Num
的{{1}}的总和。我不确定如何建立州与县之间的联系-水平。当然不是手动选择,因为我必须对50个州及其县进行此操作。我的代码是:
State