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 = "gauge"
chart.alignTicks = false
chart.plotBorderWidth = 0
chart.plotShadow = HICSSObject()
chart.plotShadow.width = 0
options.chart = chart
let title = HITitle()
title.text = "Speedometer with dual axes"
options.title = title
let pane = HIPane()
pane.startAngle = -150
pane.endAngle = 150
options.pane = pane
let yAxis1 = HIYAxis()
yAxis1.min = 0
yAxis1.max = 200
yAxis1.lineColor = HIColor(hexValue: "339")
yAxis1.tickColor = HIColor(hexValue: "339")
yAxis1.minorTickColor = HIColor(hexValue: "339")
yAxis1.offset = -25
yAxis1.lineWidth = 2
yAxis1.labels = HILabels()
yAxis1.labels.distance = -20
// yAxis1.labels.rotation = "auto"
yAxis1.tickLength = 5
yAxis1.minorTickLength = 5
yAxis1.endOnTick = false
let yAxis2 = HIYAxis()
yAxis2.min = 0
yAxis2.max = 124
yAxis2.tickPosition = "outside"
yAxis2.lineColor = HIColor(hexValue: "933")
yAxis2.lineWidth = 2
yAxis2.minorTickPosition = "outside"
yAxis2.tickColor = HIColor(hexValue: "933")
yAxis2.minorTickColor = HIColor(hexValue: "933")
yAxis2.tickLength = 5
yAxis2.minorTickLength = 5
yAxis2.labels = HILabels()
yAxis2.labels.distance = 12
// yAxis2.labels.rotation = "auto"
yAxis2.offset = -20
yAxis2.endOnTick = false
options.yAxis = [yAxis1, yAxis2]
let speed = HIGauge()
speed.name = "Speed"
speed.data = [80]
let dataLabels = HIDataLabels()
dataLabels.formatter = HIFunction(jsFunction: "function () { var kmh = this.y, mph = Math.round(kmh * 0.621); return '<span style=\"color:#339\">' + kmh + ' km/h</span><br/>' + '<span style=\"color:#933\">' + mph + ' mph</span>'; }")
speed.dataLabels = [dataLabels]
speed.tooltip = HITooltip()
speed.tooltip.valueSuffix = " km/h"
options.series = [speed]
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 = @"gauge";
chart.alignTicks = [[NSNumber alloc] initWithBool:false];
chart.plotBorderWidth = @0;
chart.plotShadow = [[NSNumber alloc] initWithBool:false];
HITitle *title = [[HITitle alloc]init];
title.text = @"Speedometer with dual axes";
HIPane *pane = [[HIPane alloc]init];
pane.startAngle = @-150;
pane.endAngle = @150;
HIYAxis *yaxis1 = [[HIYAxis alloc]init];
yaxis1.min = @0;
yaxis1.max = @200;
yaxis1.lineColor = [[HIColor alloc]initWithHexValue:@"339"];
yaxis1.tickColor = [[HIColor alloc]initWithHexValue:@"339"];
yaxis1.minorTickColor = [[HIColor alloc]initWithHexValue:@"339"];
yaxis1.offset = @-25;
yaxis1.lineWidth = @2;
yaxis1.labels = [[HILabels alloc]init];
yaxis1.labels.distance = @-20;
yaxis1.tickLength = @5;
yaxis1.minorTickLength = @5;
yaxis1.endOnTick = [[NSNumber alloc] initWithBool:false];
HIYAxis *yaxis2 = [[HIYAxis alloc]init];
yaxis2.min = @0;
yaxis2.max = @124;
yaxis2.tickPosition = @"outside";
yaxis2.lineColor = [[HIColor alloc]initWithHexValue:@"933"];
yaxis2.lineWidth = @2;
yaxis2.minorTickPosition = @"outside";
yaxis2.tickColor = [[HIColor alloc]initWithHexValue:@"933"];
yaxis2.minorTickColor = [[HIColor alloc]initWithHexValue:@"933"];
yaxis2.offset = @-20;
yaxis2.labels = [[HILabels alloc]init];
yaxis2.labels.distance = @12;
yaxis2.tickLength = @5;
yaxis2.minorTickLength = @5;
yaxis2.endOnTick = [[NSNumber alloc] initWithBool:false];
HIGauge *gauge = [[HIGauge alloc]init];
gauge.name = @"Speed";
gauge.tooltip = [[HITooltip alloc]init];
gauge.tooltip.valueSuffix = @" km/h";
gauge.dataLabels = [[HIDataLabels alloc] init];
gauge.dataLabels.formatter = [[HIFunction alloc] initWithJSFunction:@"function () { var kmh = this.y, mph = Math.round(kmh * 0.621); return '<span style=\"color:#339\">' + kmh + ' km/h</span><br/>' + '<span style=\"color:#933\">' + mph + ' mph</span>'; }"];
gauge.dataLabels.backgroundColor = [[HIColor alloc] initWithLinearGradient:@{ @"x1": @0, @"x2": @0, @"y1": @0, @"y2": @1 } stops:@[
@[@0, @"#DDD"],
@[@1, @"#FFF"]
]];
gauge.data = [NSMutableArray arrayWithObjects:@80, nil];
options.chart = chart;
options.title = title;
options.pane = pane;
options.yAxis = [NSMutableArray arrayWithObjects:yaxis1, yaxis2, nil];
options.series = [NSMutableArray arrayWithObjects: gauge, nil];
chartView.options = options;
[self.view addSubview:chartView];
}
@end