import Highcharts
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let chartView = HIChartView(frame: view.bounds)
let options = HIOptions()
let chart = HIChart()
chart.type = "pie"
chart.plotShadow = HICSSObject()
chart.plotShadow.width = 0
chart.plotBorderWidth = 0
options.chart = chart
let title = HITitle()
title.text = "Browser market shares at a specific website, 2014"
options.title = title
let tooltip = HITooltip()
tooltip.pointFormat = "{series.name}: <b>{point.percentage:.1f}%</b>"
options.tooltip = tooltip
let accessibility = HIAccessibility()
accessibility.point = HIPoint()
accessibility.point.valueSuffix = "%"
options.accessibility = accessibility
let plotOptions = HIPlotOptions()
plotOptions.pie = HIPie()
plotOptions.pie.allowPointSelect = true
plotOptions.pie.cursor = "pointer"
plotOptions.pie.colors = [
HIColor(name: "rgb(15,72,127)"),
HIColor(name: "rgb(52,109,164)"),
HIColor(name: "rgb(88,145,200)"),
HIColor(name: "rgb(124,181,236)"),
HIColor(name: "rgb(160,217,255)"),
HIColor(name: "rgb(196,253,255)"),
HIColor(name: "rgb(233,255,255)"),
HIColor(name: "rgb(255,255,255)"),
HIColor(name: "rgb(255,255,255)"),
HIColor(name: "rgb(255,255,255)")
]
let dataLabels = HIDataLabels()
dataLabels.enabled = true
dataLabels.format = "<b>{point.name}</b><br>{point.percentage:.1f} %"
dataLabels.distance = -50
dataLabels.filter = HIFilter()
dataLabels.filter.property = "percentage"
dataLabels.filter.operator = ">"
dataLabels.filter.value = 4
plotOptions.pie.dataLabels = [dataLabels]
options.plotOptions = plotOptions
let share = HIPie()
share.name = "Share"
let chromeData = HIData()
chromeData.name = "Chrome"
chromeData.y = 61.41
let internetExplorerData = HIData()
internetExplorerData.name = "Internet Explorer"
internetExplorerData.y = 11.84
let firefoxData = HIData()
firefoxData.name = "Firefox"
firefoxData.y = 10.85
let edgeData = HIData()
edgeData.name = "Edge"
edgeData.y = 4.67
let safariData = HIData()
safariData.name = "Safari"
safariData.y = 4.18
let otherData = HIData()
otherData.name = "Other"
otherData.y = 7.05
share.data = [chromeData, internetExplorerData, firefoxData, edgeData, safariData, otherData]
options.series = [share]
chartView.options = options
self.view.addSubview(chartView)
}
}
#import <UIKit/UIKit.h>
#import <Highcharts/Highcharts.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
HIChartView *chartView = [[HIChartView alloc] initWithFrame:self.view.bounds];
HIOptions *options = [[HIOptions alloc]init];
HIChart *chart = [[HIChart alloc]init];
chart.plotBackgroundColor = [[HIColor alloc]init];
chart.plotBorderWidth = [[NSNumber alloc]init];
chart.plotShadow = [[NSNumber alloc] initWithBool:false];
chart.type = @"pie";
NSArray *colors = @[
[[HIColor alloc]initWithRGB:15 green:72 blue:127],
[[HIColor alloc]initWithRGB:52 green:109 blue:164],
[[HIColor alloc]initWithRGB:88 green:145 blue:200],
[[HIColor alloc]initWithRGB:124 green:181 blue:236],
[[HIColor alloc]initWithRGB:160 green:217 blue:255],
[[HIColor alloc]initWithRGB:196 green:253 blue:255],
[[HIColor alloc]initWithRGB:233 green:255 blue:255],
[[HIColor alloc]initWithRGB:255 green:255 blue:255],
[[HIColor alloc]initWithRGB:255 green:255 blue:255],
[[HIColor alloc]initWithRGB:255 green:255 blue:255]
];
HITitle *title = [[HITitle alloc]init];
title.text = @"Browser market shares at a specific website, 2014";
HITooltip *tooltip = [[HITooltip alloc]init];
tooltip.pointFormat = @"{series.name}: <b>{point.percentage:.1f}%</b>";
HIPlotOptions *plotoptions = [[HIPlotOptions alloc]init];
plotoptions.pie = [[HIPie alloc]init];
plotoptions.pie.allowPointSelect = [[NSNumber alloc] initWithBool:true];
plotoptions.pie.cursor = @"pointer";
plotoptions.pie.dataLabels = [[HIDataLabels alloc]init];
plotoptions.pie.dataLabels.enabled = [[NSNumber alloc] initWithBool:true];
plotoptions.pie.dataLabels.format = @"<b>{point.name}</b>: {point.percentage:.1f} %";
plotoptions.pie.dataLabels.style = [[HICSSObject alloc] init];
plotoptions.pie.dataLabels.style.color = @"black";
HIPie *pie = [[HIPie alloc]init];
pie.name = @"Brands";
pie.data = @[
@{
@"name": @"Microsoft Internet Explorer",
@"y": @56.33
},
@{
@"name": @"Chrome",
@"y": @24.03,
@"sliced": [[NSNumber alloc] initWithBool:true],
@"selected": [[NSNumber alloc] initWithBool:true]
},
@{
@"name": @"Firefox",
@"y": @10.38
},
@{
@"name": @"Safari",
@"y": @4.77
},
@{
@"name": @"Opera",
@"y": @0.91
},
@{
@"name": @"Proprietary or Undetectable",
@"y": @0.2
}
];
options.chart = chart;
options.colors = colors;
options.title = title;
options.tooltip = tooltip;
options.plotOptions = plotoptions;
options.series = [NSMutableArray arrayWithObjects:pie, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end