import Highcharts
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let chartView = HIChartView(frame: view.bounds)
chartView.plugins = ["series-label"]
let options = HIOptions()
let title = HITitle()
title.text = "Solar Employment Growth by Sector, 2010-2016"
options.title = title
let subtitle = HISubtitle()
subtitle.text = "Source: thesolarfoundation.com"
options.subtitle = subtitle
let yAxis = HIYAxis()
yAxis.title = HITitle()
yAxis.title.text = "Number of Employees"
options.yAxis = [yAxis]
let xAxis = HIXAxis()
xAxis.accessibility = HIAccessibility()
xAxis.accessibility.rangeDescription = "Range: 2010 to 2017"
options.xAxis = [xAxis]
let legend = HILegend()
legend.layout = "vertical"
legend.align = "right"
legend.verticalAlign = "middle"
options.legend = legend
let plotOptions = HIPlotOptions()
plotOptions.series = HISeries()
plotOptions.series.label = HILabel()
plotOptions.series.label.connectorAllowed = false
plotOptions.series.pointStart = 2010
options.plotOptions = plotOptions
let installation = HISeries()
installation.name = "Installation"
installation.data = [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
let manufacturing = HISeries()
manufacturing.name = "Manufacturing"
manufacturing.data = [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
let salesDistribution = HISeries()
salesDistribution.name = "Sales & Distribution"
salesDistribution.data = [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
let projectDevelopment = HISeries()
projectDevelopment.name = "Project Development"
projectDevelopment.data = [NSNull(), NSNull(), 7988, 12169, 15112, 22452, 34400, 34227]
let other = HISeries()
other.name = "Other"
other.data = [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
options.series = [installation, manufacturing, salesDistribution, projectDevelopment, other]
let responsive = HIResponsive()
let rules = HIRules()
rules.condition = HICondition()
rules.condition.maxWidth = 500
rules.chartOptions = [
"legend": [
"layout": "horizontal",
"align": "center",
"verticalAlign": "bottom"
]
]
responsive.rules = [rules]
options.responsive = responsive
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];
HITitle *title = [[HITitle alloc]init];
title.text = @"Solar Employment Growth by Sector, 2010-2016";
HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"Source: thesolarfoundation.com";
HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = @"Number of Employees";
HILegend *legend = [[HILegend alloc]init];
legend.layout = @"vertical";
legend.align = @"right";
legend.verticalAlign = @"middle";
HIPlotOptions *plotoptions = [[HIPlotOptions alloc] init];
plotoptions.series = [[HISeries alloc] init];
plotoptions.series.label = [[HILabel alloc] init];
plotoptions.series.label.connectorAllowed = [[NSNumber alloc] initWithBool:false];
plotoptions.series.pointStart = @2010;
HILine *line1 = [[HILine alloc]init];
line1.name = @"Installation";
line1.data = [NSMutableArray arrayWithObjects:@43934, @52503, @57177, @69658, @97031, @119931, @137133, @154175, nil];
HILine *line2 = [[HILine alloc]init];
line2.name = @"Manufacturing";
line2.data = [NSMutableArray arrayWithObjects:@24916, @24064, @29742, @29851, @32490, @30282, @38121, @40434, nil];
HILine *line3 = [[HILine alloc]init];
line3.name = @"Sales & Distribution";
line3.data = [NSMutableArray arrayWithObjects:@11744, @17722, @16005, @19771, @20185, @24377, @32147, @39387, nil];
HILine *line4 = [[HILine alloc]init];
line4.name = @"Project Development";
line4.data = [NSMutableArray arrayWithObjects:[NSNull null], [NSNull null], @7988, @12169, @15112, @22452, @34400, @34227, nil];
HILine *line5 = [[HILine alloc]init];
line5.name = @"Other";
line5.data = [NSMutableArray arrayWithObjects:@12908, @5948, @8105, @11248, @8989, @11816, @18274, @18111, nil];
HIResponsive *responsive = [[HIResponsive alloc] init];
HIRules *rules1 = [[HIRules alloc] init];
rules1.condition = [[HICondition alloc] init];
rules1.condition.maxWidth = @500;
rules1.chartOptions = @{
@"legend" : @{
@"layout": @"horizontal",
@"align": @"center",
@"verticalAlign": @"bottom"
}
};
responsive.rules = [NSMutableArray arrayWithObjects:rules1, nil];
options.title = title;
options.subtitle = subtitle;
options.yAxis = [NSMutableArray arrayWithObject:yaxis];
options.legend = legend;
options.plotOptions = plotoptions;
options.series = [NSMutableArray arrayWithObjects:line1, line2, line3, line4, line5, nil];
options.responsive = responsive;
chartView.options = options;
[self.view addSubview:chartView];
}
@end