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];
HIChart *chart = [[HIChart alloc]init];
chart.type = @"pie";
chart.plotShadow = [[NSNumber alloc] initWithBool:false];
HITitle *title = [[HITitle alloc]init];
title.text = @"Browser market shares January, 2015 to May, 2015";
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 = [NSMutableArray arrayWithObjects:@{
@"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
}, nil];
HIOptions *options = [[HIOptions alloc]init];
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