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 = "column"
options.chart = chart
let title = HITitle()
title.text = "World\"s largest cities per 2017"
options.title = title
let subtitle = HISubtitle()
subtitle.text = "Source: <a href=\"http://en.wikipedia.org/wiki/List_of_cities_proper_by_population\">Wikipedia</a>"
options.subtitle = subtitle
let xAxis = HIXAxis()
xAxis.type = "category"
xAxis.labels = HILabels()
xAxis.labels.rotation = -45
xAxis.labels.style = HICSSObject()
xAxis.labels.style.fontSize = "13px"
xAxis.labels.style.fontFamily = "Verdana, sans-serif"
options.xAxis = [xAxis]
let yAxis = HIYAxis()
yAxis.min = 0
yAxis.title = HITitle()
yAxis.title.text = "Population (millions)"
options.yAxis = [yAxis]
let legend = HILegend()
legend.enabled = false
options.legend = legend
let tooltip = HITooltip()
tooltip.pointFormat = "Population in 2017: <b>{point.y:.1f} millions</b>"
options.tooltip = tooltip
let population = HIColumn()
population.name = "Population"
population.data = [
["Shanghai", 24.2],
["Beijing", 20.8],
["Karachi", 14.9],
["Shenzhen", 13.7],
["Guangzhou", 13.1],
["Istanbul", 12.7],
["Mumbai", 12.4],
["Moscow", 12.2],
["São Paulo", 12.0],
["Delhi", 11.7],
["Kinshasa", 11.5],
["Tianjin", 11.2],
["Lahore", 11.1],
["Jakarta", 10.6],
["Dongguan", 10.6],
["Lagos", 10.6],
["Bengaluru", 10.3],
["Seoul", 9.8],
["Foshan", 9.3],
["Tokyo", 9.3]
] as [Any]
let dataLabels = HIDataLabels()
dataLabels.enabled = true
dataLabels.rotation = -90
dataLabels.color = HIColor(hexValue: "FFFFFF")
dataLabels.align = "right"
dataLabels.format = "{point.y:.1f}" // one decimal
dataLabels.y = 10 // 10 pixels down from the top
dataLabels.style = HIStyle()
dataLabels.style.fontSize = "13px"
// dataLabels.style.fontFamily = "Verdana, sans-serif"
population.dataLabels = [dataLabels]
options.series = [population]
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.type = @"column";
HITitle *title = [[HITitle alloc]init];
title.text = @"World's largest cities per 2014";
HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"Source: <a href=\"http://en.wikipedia.org/wiki/List_of_cities_proper_by_population\">Wikipedia</a>";
HIXAxis *xaxis = [[HIXAxis alloc]init];
xaxis.type = @"category";
xaxis.labels = [[HILabels alloc]init];
xaxis.labels.rotation = @-45;
xaxis.labels.style = [[HICSSObject alloc] init];
xaxis.labels.style.fontSize = @"13px";
xaxis.labels.style.fontFamily = @"Verdana, sans-serif";
HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.min = @0;
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = @"Population (millions)";
HILegend *legend = [[HILegend alloc]init];
legend.enabled = [[NSNumber alloc] initWithBool:false];
HITooltip *tooltip = [[HITooltip alloc]init];
tooltip.pointFormat = @"Population in 2008: <b>{point.y:.1f} millions</b>";
HIColumn *column = [[HIColumn alloc]init];
column.name = @"Population";
column.data = [NSMutableArray arrayWithObjects:@[
@"Shanghai",
@23.7
],
@[
@"Lagos",
@16.1
],
@[
@"Istanbul",
@14.2
],
@[
@"Karachi",
@14
],
@[
@"Mumbai",
@12.5
],
@[
@"Moscow",
@12.1
],
@[
@"São Paulo",
@11.8
],
@[
@"Beijing",
@11.7
],
@[
@"Guangzhou",
@11.1
],
@[
@"Delhi",
@11.1
],
@[
@"Shenzhen",
@10.5
],
@[
@"Seoul",
@10.4
],
@[
@"Jakarta",
@10
],
@[
@"Kinshasa",
@9.3
],
@[
@"Tianjin",
@9.3
],
@[
@"Tokyo",
@9
],
@[
@"Cairo",
@8.9
],
@[
@"Dhaka",
@8.9
],
@[
@"Mexico City",
@8.9
],
@[
@"Lima",
@8.9
]
, nil];
column.dataLabels = [[HIDataLabels alloc]init];
column.dataLabels.enabled = [[NSNumber alloc] initWithBool:true];
column.dataLabels.rotation = @-90;
column.dataLabels.color = [[HIColor alloc]initWithHexValue:@"FFFFFF"];
column.dataLabels.align = @"right";
column.dataLabels.format = @"{point.y:.1f}";
column.dataLabels.y = @10;
column.dataLabels.style = [[HICSSObject alloc] init];
column.dataLabels.style.fontSize = @"13px";
column.dataLabels.style.fontFamily = @"Verdana, sans-serif";
options.chart = chart;
options.title = title;
options.subtitle = subtitle;
options.xAxis = [NSMutableArray arrayWithObjects:xaxis, nil];
options.yAxis = [NSMutableArray arrayWithObjects:yaxis, nil];
options.legend = legend;
options.tooltip = tooltip;
options.series = [NSMutableArray arrayWithObjects: column, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end