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
options.chart = chart
let title = HITitle()
title.text = "Browser market shares in January, 2018"
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"
let dataLabels = HIDataLabels()
dataLabels.enabled = true
dataLabels.format = "<b>{point.name}</b>: {point.percentage:.1f} %"
plotOptions.pie.dataLabels = [dataLabels]
options.plotOptions = plotOptions
let brands = HIPie()
brands.name = "Brands"
// brands.colorByPoint = true
let data1 = HIData()
data1.name = "Chrome"
data1.y = 61.41
data1.sliced = true
data1.selected = true
let data2 = HIData()
data2.name = "Internet Explorer"
data2.y = 11.84
let data3 = HIData()
data3.name = "Firefox"
data3.y = 10.85
let data4 = HIData()
data4.name = "Edge"
data4.y = 4.67
let data5 = HIData()
data5.name = "Safari"
data5.y = 4.18
let data6 = HIData()
data6.name = "Sogou Explorer"
data6.y = 1.64
let data7 = HIData()
data7.name = "Opera"
data7.y = 1.6
let data8 = HIData()
data8.name = "QQ"
data8.y = 1.2
let data9 = HIData()
data9.name = "Other"
data9.y = 2.61
brands.data = [data1, data2, data3, data4, data5, data6, data7, data8, data9]
options.series = [brands]
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 = @0;
chart.plotShadow = [[NSNumber alloc] initWithBool:false];
HITitle *title = [[HITitle alloc]init];
title.text = @"Browser<br>shares<br>2015";
title.align = @"center";
title.verticalAlign = @"middle";
title.y = @40;
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.dataLabels = [[HIDataLabels alloc]init];
plotoptions.pie.dataLabels.enabled = [[NSNumber alloc] initWithBool:true];
plotoptions.pie.dataLabels.distance = @-50;
plotoptions.pie.dataLabels.style = [[HICSSObject alloc] init];
plotoptions.pie.dataLabels.style.color = @"white";
plotoptions.pie.dataLabels.style.fontWeight = @"bold";
plotoptions.pie.dataLabels.style.textOutline = @"0px 1px 2px black";
plotoptions.pie.startAngle = @-90;
plotoptions.pie.endAngle = @90;
plotoptions.pie.center = @[@"50%", @"75%"];
HIPie *pie = [[HIPie alloc]init];
HIData *data = [[HIData alloc]init];
data.name = @"Proprietary or Undetectable";
data.y = @0.2;
data.dataLabels = @{@"enabled": [[NSNumber alloc] initWithBool:false]};
pie.name = @"Browser share";
pie.innerSize = @"50%";
pie.data = @[
@[
@"Firefox",
@10.38
],
@[
@"IE",
@56.33
],
@[
@"Chrome",
@24.03
],
@[
@"Safari",
@4.77
],
@[
@"Opera",
@0.91
],
data
];
options.chart = chart;
options.title = title;
options.tooltip = tooltip;
options.plotOptions = plotoptions;
options.series = [NSMutableArray arrayWithObjects:pie, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end