Хочет поменять цвет маркера HighCharts - PullRequest
0 голосов
/ 06 февраля 2019

Я хочу изменить цвет маркера в старших чартах https://api.highcharts.com/highcharts/plotOptions.series.marker.fillColor В приведенной выше общей ссылке она работает для Интернета, но то же самое не работает для iOS.Я попытался изменить цвет маркера, как указано в ссылке, но он не работает.

Ниже я делюсь кодом.

HIColor *color = [[HIColor alloc] initWithUIColor:[UIColor greenColor]];
HIColor *colorRed = [[HIColor alloc] initWithUIColor:[UIColor redColor]];

HIChartView *chartView = [[HIChartView alloc] initWithFrame:self.view.bounds];
chartView.backgroundColor = [UIColor orangeColor];

HIChart *chart = [[HIChart alloc] init];
chart.backgroundColor = colorRed;
chart.plotBackgroundColor = colorRed;

HIOptions *options = [[HIOptions alloc]init];

HITitle *title = [[HITitle alloc]init];
title.text = @"Solar Employment Growth by Sector, 2010-2016";

HICredits *credits = [[HICredits alloc] init];
credits.enabled = @0;

HIExporting *exporting  = [[HIExporting alloc] init];
exporting.enabled = @NO;

HIBackground *bg = [[HIBackground alloc] init];
bg.backgroundColor = colorRed;

HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"Source: thesolarfoundation.com";

HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = @"Number of Employees";

HILegend *legend = [[HILegend alloc]init];
legend.layout = @"vertical";
legend.align = @"right";
legend.verticalAlign = @"middle";

HIPlotOptions *plotoptions = [[HIPlotOptions alloc] init];
plotoptions.series = [[HISeries alloc] init];
plotoptions.series.label = [[HILabel alloc] init];
plotoptions.series.label.connectorAllowed = [[NSNumber alloc] initWithBool:false];
plotoptions.series.pointStart = @2010;
plotoptions.series.color = [[HIColor alloc] initWithUIColor:[UIColor whiteColor]];
plotoptions.series.colorIndex = @4;
plotoptions.series.marker.color =  [[HIColor alloc] initWithUIColor:[UIColor whiteColor]];
plotoptions.series.marker.fillColor = [[HIColor alloc] initWithUIColor:[UIColor whiteColor]];

HILine *line1 = [[HILine alloc]init];
line1.name = @"Installation";
line1.data = [NSMutableArray arrayWithObjects:@43934, @52503, @57177, @69658, @97031, @119931, @137133, @154175, nil];
line1.marker.fillColor = [[HIColor alloc] initWithUIColor:[UIColor whiteColor]];
line1.marker.color = [[HIColor alloc] initWithUIColor:[UIColor whiteColor]];
line1.marker.lineColor = [[HIColor alloc] initWithUIColor:[UIColor whiteColor]];

HIResponsive *responsive = [[HIResponsive alloc] init];

HIRules *rules1 = [[HIRules alloc] init];
rules1.condition = [[HICondition alloc] init];
rules1.condition.maxWidth = @500;
rules1.chartOptions = @{
                        @"legend" : @{
                                @"layout": @"horizontal",
                                @"align": @"center",
                                @"verticalAlign": @"bottom"
                                }

                        };
responsive.rules = [NSMutableArray arrayWithObjects:rules1, nil];

options.title = title;
options.subtitle = subtitle;
options.yAxis = [NSMutableArray arrayWithObject:yaxis];
options.legend = legend;
options.plotOptions = plotoptions;
options.series = [NSMutableArray arrayWithObjects:line1, nil];
options.responsive = responsive;
options.credits = credits;
options.exporting = exporting;
options.chart = chart;

chartView.options = options;
chartView.tintColor = [UIColor brownColor];

[self.view addSubview:chartView];

Заранее спасибо.

1 Ответ

0 голосов
/ 08 февраля 2019

Если вы установите цвет в plotOptions, то вам не нужно устанавливать его заново для отдельных серий.

Вам необходимо создать объект маркера: plotoptions.series.marker = [[HIMarker alloc] init];

Исправлено и работаеткод:

HIColor *color = [[HIColor alloc] initWithUIColor:[UIColor greenColor]];
HIColor *colorRed = [[HIColor alloc] initWithUIColor:[UIColor redColor]];

HIChartView *chartView = [[HIChartView alloc] initWithFrame:self.view.bounds];
chartView.backgroundColor = [UIColor orangeColor];

HIChart *chart = [[HIChart alloc] init];
chart.backgroundColor = colorRed;
chart.plotBackgroundColor = colorRed;

HIOptions *options = [[HIOptions alloc]init];

HITitle *title = [[HITitle alloc]init];
title.text = @"Solar Employment Growth by Sector, 2010-2016";

HICredits *credits = [[HICredits alloc] init];
credits.enabled = @0;

HIExporting *exporting  = [[HIExporting alloc] init];
exporting.enabled = @NO;

HIBackground *bg = [[HIBackground alloc] init];
bg.backgroundColor = colorRed;

HISubtitle *subtitle = [[HISubtitle alloc]init];
subtitle.text = @"Source: thesolarfoundation.com";

HIYAxis *yaxis = [[HIYAxis alloc]init];
yaxis.title = [[HITitle alloc]init];
yaxis.title.text = @"Number of Employees";

HILegend *legend = [[HILegend alloc]init];
legend.layout = @"vertical";
legend.align = @"right";
legend.verticalAlign = @"middle";

HIPlotOptions *plotoptions = [[HIPlotOptions alloc] init];
plotoptions.series = [[HISeries alloc] init];
plotoptions.series.label = [[HILabel alloc] init];
plotoptions.series.label.connectorAllowed = [[NSNumber alloc] initWithBool:false];
plotoptions.series.pointStart = @2010;
plotoptions.series.colorIndex = @4;
plotoptions.series.marker = [[HIMarker alloc] init];
plotoptions.series.marker.fillColor = [[HIColor alloc] initWithUIColor:[UIColor whiteColor]];

HILine *line1 = [[HILine alloc]init];
line1.name = @"Installation";
line1.data = [NSMutableArray arrayWithObjects:@43934, @52503, @57177, @69658, @97031, @119931, @137133, @154175, nil];

HIResponsive *responsive = [[HIResponsive alloc] init];

HIRules *rules1 = [[HIRules alloc] init];
rules1.condition = [[HICondition alloc] init];
rules1.condition.maxWidth = @500;
rules1.chartOptions = @{
                        @"legend" : @{
                                @"layout": @"horizontal",
                                @"align": @"center",
                                @"verticalAlign": @"bottom"
                                }

                        };
responsive.rules = [NSMutableArray arrayWithObjects:rules1, nil];

options.title = title;
options.subtitle = subtitle;
options.yAxis = [NSMutableArray arrayWithObject:yaxis];
options.legend = legend;
options.plotOptions = plotoptions;
options.series = [NSMutableArray arrayWithObjects:line1, nil];
options.responsive = responsive;
options.credits = credits;
options.exporting = exporting;
options.chart = chart;

chartView.options = options;
chartView.tintColor = [UIColor brownColor];

[self.view addSubview:chartView];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...