我想在highCharts中更改标记颜色 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];
先谢谢了。
答案 0 :(得分:0)
如果您在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];