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.zoomType = "xy"
options.chart = chart
let title = HITitle()
title.text = "Average Monthly Weather Data for Tokyo"
title.align = "left"
options.title = title
let subtitle = HISubtitle()
subtitle.text = "Source: WorldClimate.com"
subtitle.align = "left"
options.subtitle = subtitle
let xAxis = HIXAxis()
xAxis.categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
xAxis.crosshair = HICrosshair()
options.xAxis = [xAxis]
let primaryYAxis = HIYAxis()
primaryYAxis.labels = HILabels()
primaryYAxis.labels.format = "{value}°C"
primaryYAxis.labels.style = HICSSObject()
primaryYAxis.labels.style.color = "#90ed7d"
primaryYAxis.title = HITitle()
primaryYAxis.title.text = "Temperature"
primaryYAxis.title.style = HICSSObject()
primaryYAxis.title.style.color = "#90ed7d"
primaryYAxis.opposite = true
let secondaryYAxis = HIYAxis()
secondaryYAxis.gridLineWidth = 0
secondaryYAxis.title = HITitle()
secondaryYAxis.title.text = "Rainfall"
secondaryYAxis.title.style = HICSSObject()
secondaryYAxis.title.style.color = "#7cb5ec"
secondaryYAxis.labels = HILabels()
secondaryYAxis.labels.format = "{value} mm"
secondaryYAxis.labels.style = HICSSObject()
secondaryYAxis.labels.style.color = "#7cb5ec"
let tertiaryYAxis = HIYAxis()
tertiaryYAxis.gridLineWidth = 0
tertiaryYAxis.title = HITitle()
tertiaryYAxis.title.text = "Sea-Level Pressure"
tertiaryYAxis.title.style = HICSSObject()
tertiaryYAxis.title.style.color = "#434348"
tertiaryYAxis.labels = HILabels()
tertiaryYAxis.labels.format = "{value} mb"
tertiaryYAxis.labels.style = HICSSObject()
tertiaryYAxis.labels.style.color = "#434348"
tertiaryYAxis.opposite = true
options.yAxis = [primaryYAxis, secondaryYAxis, tertiaryYAxis]
let tooltip = HITooltip()
tooltip.shared = true
options.tooltip = tooltip
let legend = HILegend()
legend.layout = "vertical"
legend.align = "left"
legend.x = 80
legend.verticalAlign = "top"
legend.y = 55
legend.floating = true
legend.backgroundColor = HIColor(rgba: 255, green: 255, blue: 255, alpha: 0.25)
options.legend = legend
let rainfall = HIColumn()
rainfall.name = "Rainfall"
rainfall.yAxis = 1
rainfall.data = [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
rainfall.tooltip = HITooltip()
rainfall.tooltip.valueSuffix = " mm"
let pressure = HISpline()
pressure.name = "Sea-Level Pressure"
pressure.yAxis = 2
pressure.data = [1016, 1016, 1015.9, 1015.5, 1012.3, 1009.5, 1009.6, 1010.2, 1013.1, 1016.9, 1018.2, 1016.7]
pressure.marker = HIMarker()
pressure.marker.enabled = false
pressure.dashStyle = "shortdot"
pressure.tooltip = HITooltip()
pressure.tooltip.valueSuffix = " mb"
let temperature = HISpline()
temperature.name = "Temperature"
temperature.data = [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
temperature.tooltip = HITooltip()
temperature.tooltip.valueSuffix = " °C"
options.series = [rainfall, pressure, temperature]
let responsive = HIResponsive()
let rule = HIRules()
rule.condition = HICondition()
rule.condition.maxWidth = 500
rule.chartOptions = [
"legend": [
"floating": false,
"layout": "horizontal",
"align": "center",
"verticalAlign": "bottom",
"x": 0,
"y": 0
],
"yAxis": [
[
"showLastLabel": false,
"labels": [
"align": "right",
"x": 0,
"y": -6
]
],
[
"showLastLabel": false,
"labels": [
"align": "left",
"x": 0,
"y": -6
]
],
[
"visible": false
]
]
]
responsive.rules = [rule]
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];
HIChart *chart = [[HIChart alloc]init];
chart.zoomType = @"xy";
HITitle *title = [[HITitle alloc]init];
title.text = @"Average Monthly Weather Data for Tokyo";
HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"Source: WorldClimate.com";
HIXAxis *xaxis = [[HIXAxis alloc]init];
xaxis.categories = [NSMutableArray arrayWithObjects:@"Jan",
@"Feb",
@"Mar",
@"Apr",
@"May",
@"Jun",
@"Jul",
@"Aug",
@"Sep",
@"Oct",
@"Nov",
@"Dec"
, nil];
xaxis.crosshair = [[HICrosshair alloc]init];
HIYAxis *yaxis1 = [[HIYAxis alloc]init];
yaxis1.labels = [[HILabels alloc]init];
yaxis1.labels.format = @"{value}°C";
yaxis1.labels.style = [[HICSSObject alloc] init];
yaxis1.labels.style.color = @"#90ed7d";
yaxis1.title = [[HITitle alloc]init];
yaxis1.title.text = @"Temperature";
yaxis1.title.style = [[HICSSObject alloc] init];
yaxis1.title.style.color = @"#90ed7d";
yaxis1.opposite = [[NSNumber alloc] initWithBool:true];
HIYAxis *yaxis2 = [[HIYAxis alloc]init];
yaxis2.gridLineWidth = @0;
yaxis2.labels = [[HILabels alloc]init];
yaxis2.labels.format = @"{value} mm";
yaxis2.labels.style = [[HICSSObject alloc] init];
yaxis2.labels.style.color = @"#7cb5ec";
yaxis2.title = [[HITitle alloc]init];
yaxis2.title.text = @"Rainfall";
yaxis2.title.style = [[HICSSObject alloc] init];
yaxis2.title.style.color = @"#7cb5ec";
HIYAxis *yaxis3 = [[HIYAxis alloc]init];
yaxis3.gridLineWidth = @0;
yaxis3.labels = [[HILabels alloc]init];
yaxis3.labels.format = @"{value} mb";
yaxis3.labels.style = [[HICSSObject alloc] init];
yaxis3.labels.style.color = @"#434348";
yaxis3.title = [[HITitle alloc]init];
yaxis3.title.text = @"Sea-Level Pressure";
yaxis3.title.style = [[HICSSObject alloc] init];
yaxis3.title.style.color = @"#434348";
yaxis3.opposite = [[NSNumber alloc] initWithBool:true];
HITooltip *tooltip = [[HITooltip alloc]init];
tooltip.shared = [[NSNumber alloc] initWithBool:true];
HILegend *legend = [[HILegend alloc]init];
legend.layout = @"vertical";
legend.align = @"left";
legend.x = @80;
legend.verticalAlign = @"top";
legend.y = @60;
legend.floating = [[NSNumber alloc] initWithBool:true];
legend.backgroundColor = [[HIColor alloc]initWithHexValue:@"FFFFFF"];
HIColumn *column = [[HIColumn alloc]init];
column.name = @"Rainfall";
column.yAxis = @1;
column.data = [NSMutableArray arrayWithObjects:@49.9,
@71.5,
@106.4,
@129.2,
@144,
@176,
@135.6,
@148.5,
@216.4,
@194.1,
@95.6,
@54.4
, nil];
column.tooltip = [[HITooltip alloc]init];
column.tooltip.valueSuffix = @" mm";
HISpline *spline1 = [[HISpline alloc]init];
spline1.name = @"Sea-level Pressure";
spline1.yAxis = @2;
spline1.data = [NSMutableArray arrayWithObjects:@1016,
@1016,
@1015.9,
@1015.5,
@1012.3,
@1009.5,
@1009.6,
@1010.2,
@1013.1,
@1016.9,
@1018.2,
@1016.7, nil];
spline1.marker = [[HIMarker alloc]init];
spline1.marker.enabled = [[NSNumber alloc] initWithBool:false];
spline1.dashStyle = @"shortdot";
spline1.tooltip = [[HITooltip alloc]init];
spline1.tooltip.valueSuffix = @" mb";
HISpline *spline2 = [[HISpline alloc]init];
spline2.name = @"Temperature";
spline2.data = [NSMutableArray arrayWithObjects:@7,
@6.9,
@9.5,
@14.5,
@18.2,
@21.5,
@25.2,
@26.5,
@23.3,
@18.3,
@13.9,
@9.6, nil];
spline2.tooltip = [[HITooltip alloc]init];
spline2.tooltip.valueSuffix = @"°C";
options.chart = chart;
options.title = title;
options.subtitle = subtitle;
options.xAxis = [NSMutableArray arrayWithObjects:xaxis, nil];
options.yAxis = [NSMutableArray arrayWithObjects:yaxis1, yaxis2, yaxis3, nil];
options.tooltip = tooltip;
options.legend = legend;
options.series = [NSMutableArray arrayWithObjects: column, spline1, spline2, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end