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 chart = HIChart()
chart.type = "spline"
chart.scrollablePlotArea = HIScrollablePlotArea()
chart.scrollablePlotArea.minWidth = 600
chart.scrollablePlotArea.scrollPositionX = 1
options.chart = chart
let title = HITitle()
title.text = "Wind speed during two days"
title.align = "left"
options.title = title
let subtitle = HISubtitle()
subtitle.text = "13th & 14th of February, 2018 at two locations in Vik i Sogn, Norway"
subtitle.align = "left"
options.subtitle = subtitle
let xAxis = HIXAxis()
xAxis.type = "datetime"
xAxis.labels = HILabels()
xAxis.labels.overflow = "justify"
options.xAxis = [xAxis]
let yAxis = HIYAxis()
yAxis.title = HITitle()
yAxis.title.text = "Wind speed (m/s)"
yAxis.minorGridLineWidth = 0
yAxis.gridLineWidth = 0
let lightAir = HIPlotBands()
lightAir.from = 0.3
lightAir.to = 1.5
lightAir.color = HIColor(name: "rgba(68, 170, 213, 0.1)")
lightAir.label = HILabel()
lightAir.label.text = "Light air"
lightAir.label.style = HICSSObject()
lightAir.label.style.color = "#606060"
let lightBreeze = HIPlotBands()
lightBreeze.from = 1.5
lightBreeze.to = 3.3
lightBreeze.color = HIColor(name: "rgba(0, 0, 0, 0)")
lightBreeze.label = HILabel()
lightBreeze.label.text = "Light breeze"
lightBreeze.label.style = HICSSObject()
lightBreeze.label.style.color = "#606060"
let gentleBreeze = HIPlotBands()
gentleBreeze.from = 3.3
gentleBreeze.to = 5.5
gentleBreeze.color = HIColor(name: "rgba(68, 170, 213, 0.1)")
gentleBreeze.label = HILabel()
gentleBreeze.label.text = "Gentle breeze"
gentleBreeze.label.style = HICSSObject()
gentleBreeze.label.style.color = "#606060"
let moderateBreeze = HIPlotBands()
moderateBreeze.from = 5.5
moderateBreeze.to = 8
moderateBreeze.color = HIColor(name: "rgba(0, 0, 0, 0)")
moderateBreeze.label = HILabel()
moderateBreeze.label.text = "Moderate breeze"
moderateBreeze.label.style = HICSSObject()
moderateBreeze.label.style.color = "#606060"
let freshBreeze = HIPlotBands()
freshBreeze.from = 8
freshBreeze.to = 11
freshBreeze.color = HIColor(name: "rgba(68, 170, 213, 0.1)")
freshBreeze.label = HILabel()
freshBreeze.label.text = "Fresh breeze"
freshBreeze.label.style = HICSSObject()
freshBreeze.label.style.color = "#606060"
let strongBreeze = HIPlotBands()
strongBreeze.from = 11
strongBreeze.to = 14
strongBreeze.color = HIColor(name: "rgba(0, 0, 0, 0)")
strongBreeze.label = HILabel()
strongBreeze.label.text = "Strong breeze"
strongBreeze.label.style = HICSSObject()
strongBreeze.label.style.color = "#606060"
let highWind = HIPlotBands()
highWind.from = 14
highWind.to = 15
highWind.color = HIColor(name: "rgba(68, 170, 213, 0.1)")
highWind.label = HILabel()
highWind.label.text = "High wind"
highWind.label.style = HICSSObject()
highWind.label.style.color = "#606060"
yAxis.plotBands = [lightAir, lightBreeze, gentleBreeze, moderateBreeze, freshBreeze, strongBreeze, highWind]
options.yAxis = [yAxis]
let tooltip = HITooltip()
tooltip.valueSuffix = " m/s"
options.tooltip = tooltip
let plotOptions = HIPlotOptions()
plotOptions.spline = HISpline()
plotOptions.spline.lineWidth = 4
plotOptions.spline.states = HIStates()
plotOptions.spline.states.hover = HIHover()
plotOptions.spline.states.hover.lineWidth = 5
plotOptions.spline.marker = HIMarker()
plotOptions.spline.marker.enabled = false
plotOptions.spline.pointInterval = 3600000 // one hour
plotOptions.spline.pointStart = 1515798000000
options.plotOptions = plotOptions
let hestavollane = HISpline()
hestavollane.name = "Hestavollane"
hestavollane.data = [
3.7, 3.3, 3.9, 5.1, 3.5, 3.8, 4.0, 5.0, 6.1, 3.7, 3.3, 6.4,
6.9, 6.0, 6.8, 4.4, 4.0, 3.8, 5.0, 4.9, 9.2, 9.6, 9.5, 6.3,
9.5, 10.8, 14.0, 11.5, 10.0, 10.2, 10.3, 9.4, 8.9, 10.6, 10.5, 11.1,
10.4, 10.7, 11.3, 10.2, 9.6, 10.2, 11.1, 10.8, 13.0, 12.5, 12.5, 11.3,
10.1
]
let vik = HISpline()
vik.name = "Vik"
vik.data = [
0.2, 0.1, 0.1, 0.1, 0.3, 0.2, 0.3, 0.1, 0.7, 0.3, 0.2, 0.2,
0.3, 0.1, 0.3, 0.4, 0.3, 0.2, 0.3, 0.2, 0.4, 0.0, 0.9, 0.3,
0.7, 1.1, 1.8, 1.2, 1.4, 1.2, 0.9, 0.8, 0.9, 0.2, 0.4, 1.2,
0.3, 2.3, 1.0, 0.7, 1.0, 0.8, 2.0, 1.2, 1.4, 3.7, 2.1, 2.0,
1.5
]
options.series = [hestavollane, vik]
let navigation = HINavigation()
navigation.menuItemStyle = HICSSObject()
navigation.menuItemStyle.fontSize = "10px"
options.navigation = navigation
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 = @[ @"series-label" ];
HIOptions *options = [[HIOptions alloc]init];
HIChart *chart = [[HIChart alloc]init];
chart.type = @"spline";
chart.scrollablePlotArea = [[HIScrollablePlotArea alloc] init];
chart.scrollablePlotArea.minWidth = @600;
chart.scrollablePlotArea.scrollPositionX = @1;
HITitle *title = [[HITitle alloc]init];
title.text = @"Wind speed during two days";
HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"13th & 14th of February, 2018 at two locations in Vik i Sogn, Norway";
HIXAxis *xaxis = [[HIXAxis alloc]init];
xaxis.type = @"datetime";
xaxis.labels = [[HILabels alloc]init];
xaxis.labels.overflow = @"justify";
HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = @"Wind speed (m/s)";
yaxis.minorGridLineWidth = @0;
yaxis.gridLineWidth = @0;
yaxis.alternateGridColor = [[HIColor alloc]init];
HIPlotBands *band1 = [[HIPlotBands alloc]init];
band1.from = @0.3;
band1.to = @1.5;
band1.color = [[HIColor alloc]initWithRGBA:68 green:170 blue:213 alpha:0.1];
band1.label = [[HILabel alloc]init];
band1.label.text = @"Light air";
band1.label.style = [[HICSSObject alloc] init];
band1.label.style.color = @"#606060";
HIPlotBands *band2 = [[HIPlotBands alloc]init];
band2.from = @1.5;
band2.to = @3.3;
band2.color = [[HIColor alloc]initWithRGBA:0 green:0 blue:0 alpha:0];
band2.label = [[HILabel alloc]init];
band2.label.text = @"Light breeze";
band2.label.style = [[HICSSObject alloc] init];
band2.label.style.color = @"#606060";
HIPlotBands *band3 = [[HIPlotBands alloc]init];
band3.from = @3.3;
band3.to = @5.5;
band3.color = [[HIColor alloc]initWithRGBA:68 green:170 blue:213 alpha:0.1];
band3.label = [[HILabel alloc]init];
band3.label.text = @"Gentel breeze";
band3.label.style = [[HICSSObject alloc] init];
band3.label.style.color = @"#606060";
HIPlotBands *band4 = [[HIPlotBands alloc]init];
band4.from = @5.5;
band4.to = @8;
band4.color = [[HIColor alloc]initWithRGBA:0 green:0 blue:0 alpha:0];
band4.label = [[HILabel alloc]init];
band4.label.text = @"Moderate breeze";
band4.label.style = [[HICSSObject alloc] init];
band4.label.style.color = @"#606060";
HIPlotBands *band5 = [[HIPlotBands alloc]init];
band5.from = @8;
band5.to = @11;
band5.color = [[HIColor alloc]initWithRGBA:68 green:170 blue:213 alpha:0.1];
band5.label = [[HILabel alloc]init];
band5.label.text = @"Fresh breeze";
band5.label.style = [[HICSSObject alloc] init];
band5.label.style.color = @"#606060";
HIPlotBands *band6 = [[HIPlotBands alloc]init];
band6.from = @11;
band6.to = @14;
band6.color = [[HIColor alloc]initWithRGBA:0 green:0 blue:0 alpha:0];
band6.label = [[HILabel alloc]init];
band6.label.text = @"Strong breeze";
band6.label.style = [[HICSSObject alloc] init];
band6.label.style.color = @"#606060";
HIPlotBands *band7 = [[HIPlotBands alloc]init];
band7.from = @14;
band7.to = @15;
band7.color = [[HIColor alloc]initWithRGBA:68 green:170 blue:213 alpha:0.1];
band7.label = [[HILabel alloc]init];
band7.label.text = @"High wind";
band7.label.style = [[HICSSObject alloc] init];
band7.label.style.color = @"#606060";
yaxis.plotBands = @[band1, band2, band3, band4, band5, band6, band7];
HITooltip *tooltip = [[HITooltip alloc]init];
tooltip.valueSuffix = @" m/s";
HIPlotOptions *plotoptions = [[HIPlotOptions alloc]init];
plotoptions.spline = [[HISpline alloc]init];
plotoptions.spline.lineWidth = @4;
HIStates *state = [[HIStates alloc]init];
state.hover = [[HIHover alloc]init];
state.hover.lineWidth = @5;
plotoptions.spline.states = state;
plotoptions.spline.marker = [[HIMarker alloc]init];
plotoptions.spline.marker.enabled = [[NSNumber alloc] initWithBool:false];
plotoptions.spline.pointInterval = @3600000;
plotoptions.spline.pointStart = @1433030400000;
HISpline *spline1 = [[HISpline alloc]init];
spline1.name = @"Hestavollane";
spline1.data = @[
@0.2,
@0.8,
@0.8,
@0.8,
@1,
@1.3,
@1.5,
@2.9,
@1.9,
@2.6,
@1.6,
@3,
@4,
@3.6,
@4.5,
@4.2,
@4.5,
@4.5,
@4,
@3.1,
@2.7,
@4,
@2.7,
@2.3,
@2.3,
@4.1,
@7.7,
@7.1,
@5.6,
@6.1,
@5.8,
@8.6,
@7.2,
@9,
@10.9,
@11.5,
@11.6,
@11.1,
@12,
@12.3,
@10.7,
@9.4,
@9.8,
@9.6,
@9.8,
@9.5,
@8.5,
@7.4,
@7.6
];
HISpline *spline2 = [[HISpline alloc]init];
spline2.name = @"Vik";
spline2.data = @[
@0,
@0,
@0.6,
@0.9,
@0.8,
@0.2,
@0,
@0,
@0,
@0.1,
@0.6,
@0.7,
@0.8,
@0.6,
@0.2,
@0,
@0.1,
@0.3,
@0.3,
@0,
@0.1,
@0,
@0,
@0,
@0.2,
@0.1,
@0,
@0.3,
@0,
@0.1,
@0.2,
@0.1,
@0.3,
@0.3,
@0,
@3.1,
@3.1,
@2.5,
@1.5,
@1.9,
@2.1,
@1,
@2.3,
@1.9,
@1.2,
@0.7,
@1.3,
@0.4,
@0.3
];
HINavigation *navigation = [[HINavigation alloc]init];
navigation.menuItemStyle = [[HICSSObject alloc] init];
navigation.menuItemStyle.fontSize = @"10px";
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.navigation = navigation;
options.series = [NSMutableArray arrayWithObjects:spline1, spline2, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end