gpt4 book ai didi

iOS-Charts 在圆圈下方绘制值

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:32:11 31 4
gpt4 key购买 nike

我正在使用 Daniel Gindi 的图表。正常情况下,值在圆圈上方;

values above the circles

1- 但是当没有足够的标签空间(因为线条)时,我需要将值/标签下拉到圆圈下方

2- 我需要在圆圈和标签/值之间提供额外的偏移量。

3- 我只需要在第一个和最后一个值上显示圆圈。

我正在使用 valueFormatter 作为数据集委托(delegate)。我可以达到它

-(NSString *)stringForValue:(double)value entry:(ChartDataEntry *)entry 
dataSetIndex:(NSInteger)dataSetIndex viewPortHandler:
(ChartViewPortHandler *)viewPortHandler{
if (entry.x==0||entry.x==myArray.count-1) {
NSInteger index = [NSNumber numberWithDouble:value].integerValue;
return [NSString stringWithFormat:@"%ld",(long)index];
} else {
return @"";
}

但我不知道该怎么办。

提前致谢。

最佳答案

也许您可以使用折线图来解决您的 3.question。如果你从 github 下载 ChartDemo 应用程序,找到 LineChart1ViewController.m 并更改 - (void)setDataCount:(int)count range:(double)range 方法内容以此

- (void)setDataCount:(int)count range:(double)range {
NSMutableArray *values = [[NSMutableArray alloc] init];

for (int i = 0; i < count; i++)
{
double val = arc4random_uniform(range) + 3;
if(i == 0 || i == count - 1)
[values addObject:[[ChartDataEntry alloc] initWithX:i y:val icon: [UIImage imageNamed:@"icon"]]];
else
[values addObject:[[ChartDataEntry alloc] initWithX:i y:val icon: [UIImage imageNamed:@""]]];
}

LineChartDataSet *set1 = nil;
if (_chartView.data.dataSetCount > 0)
{
set1 = (LineChartDataSet *)_chartView.data.dataSets[0];
set1.values = values;
[_chartView.data notifyDataChanged];
[_chartView notifyDataSetChanged];
}
else
{
set1 = [[LineChartDataSet alloc] initWithValues:values label:@"DataSet 1"];

set1.drawIconsEnabled = YES;

set1.lineDashLengths = @[@5.f, @2.5f];
set1.highlightLineDashLengths = @[@5.f, @2.5f];
[set1 setColor:UIColor.blackColor];
[set1 setCircleColor:UIColor.blackColor];
set1.lineWidth = 1.0;
set1.circleRadius = 0.0;
set1.drawCircleHoleEnabled = NO;
set1.valueFont = [UIFont systemFontOfSize:9.f];
set1.formLineDashLengths = @[@5.f, @2.5f];
set1.formLineWidth = 1.0;
set1.formSize = 15.0;

NSArray *gradientColors = @[
(id)[ChartColorTemplates colorFromString:@"#00ff0000"].CGColor,
(id)[ChartColorTemplates colorFromString:@"#ffff0000"].CGColor
];
CGGradientRef gradient = CGGradientCreateWithColors(nil, (CFArrayRef)gradientColors, nil);

set1.fillAlpha = 1.f;
set1.fill = [ChartFill fillWithLinearGradient:gradient angle:90.f];
set1.drawFilledEnabled = YES;

CGGradientRelease(gradient);

NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];

LineChartData *data = [[LineChartData alloc] initWithDataSets:dataSets];

_chartView.data = data;}}

我的意思是您可以在设置 0.0f 圆半径后为第一个和最后一个圆使用(自定义看起来像圆等)图标。看起来像这样

enter image description here

玩得开心:)

关于iOS-Charts 在圆圈下方绘制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45557785/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com