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 = "bar"
options.chart = chart
let title = HITitle()
title.text = "Historic World Population by Region"
options.title = title
let subtitle = HISubtitle()
subtitle.text = "Source: <a href=\"https://en.wikipedia.org/wiki/World_population\">Wikipedia.org</a>"
options.subtitle = subtitle
let xAxis = HIXAxis()
xAxis.categories = ["Africa", "America", "Asia", "Europe", "Oceania"]
options.xAxis = [xAxis]
let yAxis = HIYAxis()
yAxis.min = 0
yAxis.title = HITitle()
yAxis.title.text = "Population (millions)"
yAxis.title.align = "high"
yAxis.labels = HILabels()
yAxis.labels.overflow = "justify"
options.yAxis = [yAxis]
let tooltip = HITooltip()
tooltip.valueSuffix = " millions"
options.tooltip = tooltip
let plotOptions = HIPlotOptions()
plotOptions.bar = HIBar()
let dataLabels = HIDataLabels()
dataLabels.enabled = true
plotOptions.bar.dataLabels = [dataLabels]
options.plotOptions = plotOptions
let legend = HILegend()
legend.layout = "vertical"
legend.align = "right"
legend.verticalAlign = "top"
legend.x = -40
legend.y = 80
legend.floating = true
legend.borderWidth = 1
legend.backgroundColor = HIColor(hexValue: "FFFFFF")
legend.shadow = HICSSObject()
legend.shadow.opacity = 1
options.legend = legend
let credits = HICredits()
credits.enabled = false
options.credits = credits
let year1800 = HIBar()
year1800.name = "Year 1800"
year1800.data = [107, 31, 635, 203, 2]
let year1900 = HIBar()
year1900.name = "Year 1900"
year1900.data = [133, 156, 947, 408, 6]
let year2000 = HIBar()
year2000.name = "Year 2000"
year2000.data = [814, 841, 3714, 727, 31]
let year2016 = HIBar()
year2016.name = "Year 2016"
year2016.data = [1216, 1001, 4436, 738, 40]
options.series = [year1800, year1900, year2000, year2000]
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 = @"bar";
HITitle *title = [[HITitle alloc]init];
title.text = @"Historic World Population by Region";
HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"Source: <a href=\"https://en.wikipedia.org/wiki/World_population\">Wikipedia.org</a>";
HIXAxis * xaxis = [[HIXAxis alloc]init];
xaxis.categories = [NSMutableArray arrayWithObjects:@"Africa",
@"America",
@"Asia",
@"Europe",
@"Oceania", nil];
HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.min = @0;
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = @"Population (millions)";
yaxis.title.align = @"high";
yaxis.labels = [[HILabels alloc]init];
yaxis.labels.overflow = @"justify";
HITooltip *tooltip = [[HITooltip alloc]init];
tooltip.valueSuffix = @" millions";
HIPlotOptions *plotOptions = [[HIPlotOptions alloc]init];
plotOptions.bar = [[HIBar alloc]init];
plotOptions.bar.dataLabels = [[HIDataLabels alloc]init];
plotOptions.bar.dataLabels.enabled = [[NSNumber alloc] initWithBool:true];
HILegend *legend = [[HILegend alloc]init];
legend.layout = @"vertical";
legend.align = @"right";
legend.verticalAlign = @"top";
legend.x = @-40;
legend.y = @80;
legend.floating = [[NSNumber alloc] initWithBool:true];
legend.borderWidth = @1;
legend.backgroundColor = [[HIColor alloc]initWithHexValue:@"FFFFFF"];
legend.shadow = [[NSNumber alloc] initWithBool:true];
HICredits *credits = [[HICredits alloc]init];
credits.enabled = [[NSNumber alloc] initWithBool:false];
HIBar *bar1 = [[HIBar alloc]init];
bar1.name = @"Year 1800";
bar1.data = [NSMutableArray arrayWithObjects:@107,
@31,
@635,
@203,
@2, nil];
HIBar *bar2 = [[HIBar alloc]init];
bar2.name = @"Year 1900";
bar2.data = [NSMutableArray arrayWithObjects:@133,
@156,
@947,
@408,
@6, nil];
HIBar *bar3 = [[HIBar alloc]init];
bar3.name = @"Year 2012";
bar3.data = [NSMutableArray arrayWithObjects:@1052,
@954,
@4250,
@740,
@38, nil];
HIOptions *options = [[HIOptions alloc]init];
options.chart = chart;
options.title = title;
options.subtitle = subtitle;
options.xAxis = [NSMutableArray arrayWithObjects:xaxis, nil];
options.yAxis = [NSMutableArray arrayWithObjects:yaxis, nil];
options.tooltip = tooltip;
options.plotOptions = plotOptions;
options.legend = legend;
options.credits = credits;
options.series = [NSMutableArray arrayWithObjects:bar1, bar2, bar3, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end