import Highcharts
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let chartView = HIChartView(frame: view.bounds)
chartView.plugins = ["sankey", "organization"]
let options = HIOptions()
let chart = HIChart()
chart.height = 600
chart.inverted = true
options.chart = chart
let title = HITitle()
title.text = "Highcharts Org Chart"
options.title = title
let accessibility = HIAccessibility()
accessibility.point = HIPoint()
accessibility.point.descriptionFormatter = HIFunction(jsFunction: "function (point) { var nodeName = point.toNode.name, nodeId = point.toNode.id, nodeDesc = nodeName === nodeId ? nodeName : nodeName + ', ' + nodeId, parentDesc = point.fromNode.id; return point.index + '. ' + nodeDesc + ', reports to ' + parentDesc + '.'; }")
options.accessibility = accessibility
let highsoft = HIOrganization()
highsoft.name = "Highsoft"
highsoft.keys = ["from", "to"]
highsoft.data = [
["Shareholders", "Board"],
["Board", "CEO"],
["CEO", "CTO"],
["CEO", "CPO"],
["CEO", "CSO"],
["CEO", "CMO"],
["CEO", "HR"],
["CTO", "Product"],
["CTO", "Web"],
["CSO", "Sales"],
["CMO", "Market"]
]
let level0 = HILevels()
level0.level = 0
level0.color = HIColor(name: "silver")
level0.dataLabels = HIDataLabels()
level0.dataLabels.color = HIColor(name: "black")
let level1 = HILevels()
level1.level = 1
level1.color = HIColor(name: "silver")
level1.dataLabels = HIDataLabels()
level1.dataLabels.color = HIColor(name: "black")
let level2 = HILevels()
level2.level = 2
level2.color = HIColor(hexValue: "980104")
let level4 = HILevels()
level4.level = 4
level4.color = HIColor(hexValue: "359154")
highsoft.levels = [level0, level1, level2, level4]
let shareholders = HINodes()
shareholders.id = "Shareholders"
let board = HINodes()
board.id = "Board"
let ceo = HINodes()
ceo.id = "CEO"
ceo.title = "CEO"
ceo.name = "Grethe Hjetland"
ceo.image = "https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg"
let hr = HINodes()
hr.id = "HR"
hr.title = "HR/CFO"
hr.name = "Anne Jorunn Fjærestad"
hr.color = HIColor(name: "007ad0")
hr.image = "https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg"
hr.column = 3
hr.offset = "75%"
let cto = HINodes()
cto.id = "CTO"
cto.title = "CTO"
cto.name = "Christer Vasseng"
cto.column = 4
cto.image = "https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg"
cto.layout = "hanging"
let cpo = HINodes()
cpo.id = "CPO"
cpo.title = "CPO"
cpo.name = "Torstein Hønsi"
cpo.column = 4
cpo.image = "https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12131849/Torstein1.jpg"
let cso = HINodes()
cso.id = "CSO"
cso.title = "CSO"
cso.name = "Anita Nesse"
cso.column = 4
cso.image = "https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132313/Anita.jpg"
cso.layout = "hanging"
let cmo = HINodes()
cmo.id = "CMO"
cmo.title = "CMO"
cmo.name = "Vidar Brekke"
cmo.column = 4
cmo.image = "https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/13105551/Vidar.jpg"
cmo.layout = "hanging"
let product = HINodes()
product.id = "Product"
product.title = "Product developers"
let web = HINodes()
web.id = "Web"
web.title = "Web devs, sys admin"
let sales = HINodes()
sales.id = "Sales"
sales.title = "Sales team"
let market = HINodes()
market.id = "Market"
market.title = "Marketing team"
highsoft.nodes = [shareholders, board, ceo, hr, cto, cpo, cso, cmo, product, web, sales, market]
highsoft.colorByPoint = false
highsoft.color = HIColor(hexValue: "007ad0")
let dataLabels = HIDataLabels()
dataLabels.color = HIColor(name: "white")
highsoft.dataLabels = [dataLabels]
highsoft.borderColor = HIColor(name: "white")
highsoft.nodeWidth = 65
options.series = [highsoft]
let tooltip = HITooltip()
tooltip.outside = true
options.tooltip = tooltip
let exporting = HIExporting()
exporting.allowHTML = true
exporting.sourceWidth = 800
exporting.sourceHeight = 600
options.exporting = exporting
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];
chartView.plugins = @[@"sankey", @"organization"];
HIOptions *options = [[HIOptions alloc]init];
HIChart *chart = [[HIChart alloc]init];
chart.height = @600;
chart.inverted = [[NSNumber alloc] initWithBool:true];
options.chart = chart;
HITitle *title = [[HITitle alloc]init];
title.text = @"Highcharts Org Chart";
options.title = title;
HITooltip *tooltip = [[HITooltip alloc] init];
tooltip.outside = [[NSNumber alloc] initWithBool:true];
options.tooltip = tooltip;
HIExporting *exporting = [[HIExporting alloc] init];
exporting.allowHTML = [[NSNumber alloc] initWithBool:true];
exporting.sourceWidth = @800;
exporting.sourceHeight = @600;
options.exporting = exporting;
HIOrganization *series = [[HIOrganization alloc] init];
series.name = @"Highsoft";
series.keys = @[@"from", @"to"];
series.data = @[
@[@"Shareholders", @"Board"],
@[@"Board", @"CEO"],
@[@"CEO", @"CTO"],
@[@"CEO", @"CPO"],
@[@"CEO", @"CSO"],
@[@"CEO", @"CMO"],
@[@"CEO", @"HR"],
@[@"CTO", @"Product"],
@[@"CTO", @"Web"],
@[@"CSO", @"Sales"],
@[@"CMO", @"Market"],
];
HILevels *level1 = [[HILevels alloc] init];
level1.level = @0;
level1.color = [[HIColor alloc] initWithName:@"silver"];
level1.dataLabels = [[HIDataLabels alloc] init];
level1.dataLabels.color = [[HIColor alloc] initWithName:@"black"];
// level1.height = @25;
HILevels *level2 = [[HILevels alloc] init];
level2.level = @1;
level2.color = [[HIColor alloc] initWithName:@"silver"];
level2.dataLabels = [[HIDataLabels alloc] init];
level2.dataLabels.color = [[HIColor alloc] initWithName:@"black"];
// level2.height = @25;
HILevels *level3 = [[HILevels alloc] init];
level3.level = @2;
level3.color = [[HIColor alloc] initWithHexValue:@"980104"];
HILevels *level4 = [[HILevels alloc] init];
level4.level = @4;
level4.color = [[HIColor alloc] initWithHexValue:@"359154"];
series.levels = [NSArray arrayWithObjects:level1, level2, level3, level4, nil];
HINodes *node1 = [[HINodes alloc] init];
node1.id = @"Shareholders";
HINodes *node2 = [[HINodes alloc] init];
node2.id = @"Board";
HINodes *node3 = [[HINodes alloc] init];
node3.id = @"CEO";
node3.title = @"CEO";
node3.name = @"Grethe Hjetland";
node3.image = @"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg";
HINodes *node4 = [[HINodes alloc] init];
node4.id = @"HR";
node4.title = @"HR/CFO";
node4.name = @"Anne Jorunn Fjærestad";
node4.color = [[HIColor alloc] initWithHexValue:@"007ad0"];
node4.image = @"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132314/AnneJorunn.jpg";
node4.column = @3;
node4.offset = @"75%";
HINodes *node5 = [[HINodes alloc] init];
node5.id = @"CTO";
node5.title = @"CTO";
node5.name = @"Christer Vasseng";
node5.image = @"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg";
node5.column = @4;
node5.layout = @"hanging";
HINodes *node6 = [[HINodes alloc] init];
node6.id = @"CPO";
node6.title = @"CPO";
node6.name = @"Torstein Hønsi";
node6.image = @"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12131849/Torstein1.jpg";
node6.column = @4;
HINodes *node7 = [[HINodes alloc] init];
node7.id = @"CSO";
node7.title = @"CSO";
node7.name = @"Anita Nesse";
node7.image = @"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132313/Anita.jpg";
node7.column = @4;
node7.layout = @"hanging";
HINodes *node8 = [[HINodes alloc] init];
node8.id = @"CMO";
node8.title = @"CMO";
node8.name = @"Vidar Brekke";
node8.image = @"https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/13105551/Vidar.jpg";
node8.column = @4;
node8.layout = @"hanging";
HINodes *node9 = [[HINodes alloc] init];
node9.id = @"Product";
node9.name = @"Product developers";
HINodes *node10 = [[HINodes alloc] init];
node10.id = @"Web";
node10.name = @"General tech";
node10.definition = @"Web developers, sys admin";
HINodes *node11 = [[HINodes alloc] init];
node11.id = @"Sales";
node11.name = @"Sales team";
HINodes *node12 = [[HINodes alloc] init];
node12.id = @"Market";
node12.name = @"Marketing team";
series.nodes = [NSArray arrayWithObjects:node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, node11, node12, nil];
series.colorByPoint = [[NSNumber alloc] initWithBool:false];
series.color = [[HIColor alloc] initWithHexValue:@"007ad0"];
HIDataLabels *dataLabels = [[HIDataLabels alloc] init];
dataLabels.color = [[HIColor alloc] initWithName:@"white"];
series.dataLabels = [NSArray arrayWithObjects:dataLabels, nil];
series.borderColor = [[HIColor alloc] initWithName:@"white"];
series.nodeWidth = @65;
options.series = @[series];
chartView.options = options;
[self.view addSubview:chartView];
}
@end