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 = "scatter"
chart.margin = [70, 50, 60, 80]
chart.events = HIEvents()
chart.events.click = HIFunction(jsFunction: "function (e) { var x = Math.round(e.xAxis[0].value), y = Math.round(e.yAxis[0].value), series = this.series[0]; series.addPoint([x, y]); }")
options.chart = chart
let title = HITitle()
title.text = "Live random data"
options.title = title
let subtitle = HISubtitle()
subtitle.text = "Click the plot area to add a point. Click a point to remove it."
options.subtitle = subtitle
let accessibility = HIAccessibility()
accessibility.announceNewData = HIAnnounceNewData()
accessibility.announceNewData.enabled = true
options.accessibility = accessibility
let xAxis = HIXAxis()
xAxis.gridLineWidth = 1
xAxis.minPadding = 0.2
xAxis.maxPadding = 0.2
// xAxis.maxZoom = 60
options.xAxis = [xAxis]
let yAxis = HIYAxis()
yAxis.title = HITitle()
yAxis.title.text = "Value"
yAxis.minPadding = 0.2
yAxis.maxPadding = 0.2
// yAxis.maxZoom = 60
let plotLines = HIPlotLines()
plotLines.value = 0
plotLines.width = 1
plotLines.color = HIColor(hexValue: "808080")
yAxis.plotLines = [plotLines]
options.yAxis = [yAxis]
let legend = HILegend()
legend.enabled = false
options.legend = legend
let exporting = HIExporting()
exporting.enabled = false
options.exporting = exporting
let plotOptions = HIPlotOptions()
plotOptions.scatter = HIScatter()
plotOptions.scatter.lineWidth = 1
plotOptions.scatter.point = HIPoint()
plotOptions.scatter.point.events = HIEvents()
plotOptions.scatter.point.events.click = HIFunction(jsFunction: "function () { if (this.series.data.length > 1) { this.remove(); } }")
options.plotOptions = plotOptions
let scatter = HIScatter()
scatter.data = [[20, 20], [80, 80]]
options.series = [scatter]
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 = @"scatter";
chart.margin = [NSMutableArray arrayWithObjects:@70, @50, @60, @80, nil];
HIEvents *events = [[HIEvents alloc] init];
events.click = [[HIFunction alloc] initWithJSFunction:@"function (e) { var x = Math.round(e.xAxis[0].value), y = Math.round(e.yAxis[0].value), series = this.series[0]; series.addPoint([x, y]); }"];
chart.events = events;
HITitle *title = [[HITitle alloc]init];
title.text = @"User supplied data";
HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"Click the plot area to add a point. Click a point to remove it.";
HIXAxis *xaxis = [[HIXAxis alloc]init];
xaxis.gridLineWidth = @1;
xaxis.minPadding = @0.2;
xaxis.maxPadding = @0.2;
// xaxis.maxZoom = @60;
HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.title = [[HITitle alloc] init];
yaxis.title.text = @"Value";
yaxis.minPadding = @0.2;
yaxis.maxPadding = @0.2;
// yaxis.maxZoom = @60;
HIPlotLines *plotLines = [[HIPlotLines alloc] init];
plotLines.value = @0;
plotLines.width = @1;
plotLines.color = [[HIColor alloc] initWithHexValue:@"808080"];
yaxis.plotLines = [NSMutableArray arrayWithObjects:plotLines, nil];
HILegend *legend = [[HILegend alloc] init];
legend.enabled = [[NSNumber alloc] initWithBool:false];
HIExporting *exporting = [[HIExporting alloc] init];
exporting.enabled = [[NSNumber alloc] initWithBool:false];
HIPlotOptions *plotOptions = [[HIPlotOptions alloc] init];
plotOptions.series = [[HISeries alloc] init];
plotOptions.series.lineWidth = @1;
plotOptions.series.point = [[HIPoint alloc] init];
plotOptions.series.point.events = [[HIEvents alloc] init];
plotOptions.series.point.events.click = [[HIFunction alloc] initWithJSFunction:@"function () { if (this.series.data.length > 1) { this.remove(); } }"];
HIScatter *scatter = [[HIScatter alloc] init];
scatter.data =[NSMutableArray arrayWithObjects:@[@20, @20], @[@80, @80], nil];
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.exporting = exporting;
options.plotOptions = plotOptions;
options.series = [NSMutableArray arrayWithObjects:scatter, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end