import Highcharts
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let chartView = HIChartView(frame: view.bounds)
let options = HIOptions()
let title = HITitle()
title.text = "Highcharts Box Plot Example"
options.title = title
let legend = HILegend()
legend.enabled = false
options.legend = legend
let xAxis = HIXAxis()
xAxis.categories = ["1", "2", "3", "4", "5"]
xAxis.title = HITitle()
xAxis.title.text = "Experiment No."
options.xAxis = [xAxis]
let yAxis = HIYAxis()
yAxis.title = HITitle()
yAxis.title.text = "Observations"
let plotLine = HIPlotLines()
plotLine.value = 932
plotLine.color = HIColor(name: "red")
plotLine.width = 1
plotLine.label = HILabel()
plotLine.label.text = "Theoretical mean: 932"
plotLine.label.align = "center"
plotLine.label.style = HICSSObject()
plotLine.label.style.color = "gray"
yAxis.plotLines = [plotLine]
options.yAxis = [yAxis]
let observations = HIBoxplot()
observations.name = "Observations"
observations.data = [
[760, 801, 848, 895, 965],
[733, 853, 939, 980, 1080],
[714, 762, 817, 870, 918],
[724, 802, 806, 871, 950],
[834, 836, 864, 882, 910]
]
observations.tooltip = HITooltip()
observations.tooltip.headerFormat = "<em>Experiment No {point.key}</em><br/>"
let outliers = HIScatter()
outliers.name = "Outliers"
outliers.color = HIColor(hexValue: "7cb5ec")
outliers.data = [ // x, y positions where 0 is the first category
[0, 644],
[4, 718],
[4, 951],
[4, 969]
]
outliers.marker = HIMarker()
outliers.marker.fillColor = HIColor(name: "white")
outliers.marker.lineWidth = 1
outliers.marker.lineColor = "#7cb5ec"
outliers.tooltip = HITooltip()
outliers.tooltip.pointFormat = "Observation: {point.y}"
options.series = [observations, outliers]
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 = @"boxplot";
HITitle *title = [[HITitle alloc]init];
title.text = @"Highcharts Box Plot Example";
HILegend *legend = [[HILegend alloc]init];
legend.enabled = [[NSNumber alloc] initWithBool:false];
HIXAxis *xaxis = [[HIXAxis alloc]init];
xaxis.categories = [NSMutableArray arrayWithObjects:@"1",
@"2",
@"3",
@"4",
@"5", nil];
xaxis.title = [[HITitle alloc]init];
xaxis.title.text = @"Experiment No.";
HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = @"Observations";
HIPlotLines *plotlines = [[HIPlotLines alloc]init];
plotlines.value = @932;
plotlines.color = [[HIColor alloc]initWithName:@"red"];
plotlines.width = @1;
plotlines.label = [[HILabel alloc]init];
plotlines.label.text = @"Theoretical mean: 932";
plotlines.label.align = @"center";
plotlines.label.style = [[HICSSObject alloc] init];
plotlines.label.style.color = @"gray";
yaxis.plotLines = [NSMutableArray arrayWithObject:plotlines];
HIBoxplot *series1 = [[HIBoxplot alloc]init];
series1.name = @"Observations";
series1.data = [NSMutableArray arrayWithObjects:@[
@760,
@801,
@848,
@895,
@965
],
@[
@733,
@853,
@939,
@980,
@1080
],
@[
@714,
@762,
@817,
@870,
@918
],
@[
@724,
@802,
@806,
@871,
@950
],
@[
@834,
@836,
@864,
@882,
@910
], nil];
series1.tooltip = [[HITooltip alloc]init];
series1.tooltip.headerFormat = @"<em>Experiment No {point.key}</em><br/>";
HIScatter *series2 = [[HIScatter alloc]init];
series2.name = @"Outliner";
series2.color = [[HIColor alloc]initWithHexValue:@"7cb5ec"];
series2.data = [NSMutableArray arrayWithObjects:@[
@0,
@644
],
@[
@4,
@718
],
@[
@4,
@951
],
@[
@4,
@969
], nil];
series2.marker = [[HIMarker alloc]init];
series2.marker.fillColor = [[HIColor alloc]initWithName:@"white"];
series2.marker.lineWidth = @1;
series2.marker.lineColor = [[HIColor alloc]initWithHexValue:@"7cb5ec"];
series2.tooltip = [[HITooltip alloc]init];
series2.tooltip.pointFormat = @"Observation: {point.y}";
options.chart = chart;
options.title = title;
options.legend = legend;
options.xAxis = [NSMutableArray arrayWithObject:xaxis];
options.yAxis = [NSMutableArray arrayWithObject:yaxis];
options.series = [NSMutableArray arrayWithObjects:series1, series2, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end