Git Product home page Git Product logo

Comments (3)

eddOrnelas avatar eddOrnelas commented on June 27, 2024

Asking the same thing :D

from charts.

myDonghao avatar myDonghao commented on June 27, 2024

Asking the same thing :D

- (void)setTestData1 {
    
    
    ChartLimitLine *maxLine = [[ChartLimitLine alloc] initWithLimit:80 label:@"80"];
    maxLine.valueFont = [UIFont systemFontOfSize:8];
    maxLine.lineWidth = 1;
    maxLine.labelPosition = ChartLimitLabelPositionRightTop;
    maxLine.lineColor = [UIColor qmui_colorWithHexString:@"#FFA200"];
    [self.chartView.leftAxis addLimitLine:maxLine];
    
    ChartLimitLine *minLine = [[ChartLimitLine alloc] initWithLimit:60 label:@"60"];
    minLine.valueFont = [UIFont systemFontOfSize:8];
    minLine.lineWidth = 1;
    minLine.labelPosition = ChartLimitLabelPositionRightTop;
    minLine.lineColor = [UIColor redColor];
    [self.chartView.leftAxis addLimitLine:minLine];
    
    NSMutableArray *dataSets = [NSMutableArray array];
    
    // 第一段
    {
        NSMutableArray *firstValue = [NSMutableArray array];
        for (int i = 0; i < 10; i++) {
            // value 是 0 - 60 的随机数
            int value = [self getRandomNumber:60 to:80];
            ChartDataEntry *entry = [[ChartDataEntry alloc] initWithX:i y:value];
            [firstValue addObject:entry];
            
        }
        ChartDataEntry *entry = [[ChartDataEntry alloc] initWithX:10 y:60];
        [firstValue addObject:entry];
        LineChartDataSet *dataSet = [[LineChartDataSet alloc] initWithEntries:firstValue];
        dataSet.drawFilledEnabled = YES;
        dataSet.drawCirclesEnabled = YES;
        dataSet.drawCircleHoleEnabled = YES;
        dataSet.circleHoleColor = UIColor.whiteColor;
        
        dataSet.circleColors = @[
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor qmui_colorWithHexString:@"#FFA200"],
            [UIColor clearColor]
        ];
        dataSet.circleRadius = 3;
        dataSet.circleHoleRadius = 1;
        dataSet.lineWidth = 1;
        dataSet.mode = LineChartModeCubicBezier;
        dataSet.drawValuesEnabled = NO;
        NSArray *fillColors = @[
            (id)[ChartColorTemplates colorFromString:@"#00FFA200"].CGColor,
            (id)[ChartColorTemplates colorFromString:@"#FFFFA200"] .CGColor,
        ];
        CGGradientRef gradient = CGGradientCreateWithColors(nil, (CFArrayRef)fillColors, nil);
        dataSet.fillAlpha = 1.f;
        dataSet.fill = [[ChartLinearGradientFill alloc] initWithGradient:gradient angle:90.0f];

        [dataSet setColors:@[
            [UIColor qmui_colorWithHexString:@"#FFA200"],
       ]];
        [dataSets addObject:dataSet];
    }

    // 第二段
    {
    NSMutableArray *firstValue = [NSMutableArray array];
    ChartDataEntry *entry = [[ChartDataEntry alloc] initWithX:10 y:60];
    [firstValue addObject:entry];
    for (int i = 11; i < 20; i++) {
        int value = [self getRandomNumber:00 to:60];
        ChartDataEntry *entry = [[ChartDataEntry alloc] initWithX:i y:value];
        [firstValue addObject:entry];
        
    }
    
    LineChartDataSet *dataSet = [[LineChartDataSet alloc] initWithEntries:firstValue];
    dataSet.drawFilledEnabled = YES;
    dataSet.drawCirclesEnabled = YES;
    dataSet.drawCircleHoleEnabled = YES;
    dataSet.circleHoleColor = UIColor.whiteColor;
   
    dataSet.circleColors = @[
        [UIColor clearColor],
        [UIColor redColor],
        [UIColor redColor],
        [UIColor redColor],
        [UIColor redColor],
        [UIColor redColor],
        [UIColor redColor],
        [UIColor redColor],
        [UIColor redColor],
        [UIColor redColor]
    ];
    dataSet.circleRadius = 3;
    dataSet.circleHoleRadius = 1;
    dataSet.lineWidth = 1;
    dataSet.mode = LineChartModeCubicBezier;
    dataSet.drawValuesEnabled = NO;
    NSArray *fillColors = @[
        (id)[ChartColorTemplates colorFromString:@"#00FF0000"].CGColor,
        (id)[ChartColorTemplates colorFromString:@"#FFFF0000"] .CGColor,
    ];
    CGGradientRef gradient = CGGradientCreateWithColors(nil, (CFArrayRef)fillColors, nil);
    dataSet.fillAlpha = 1.f;
    dataSet.fill = [[ChartLinearGradientFill alloc] initWithGradient:gradient angle:90.0f];
    
    [dataSet setColors:@[
        [UIColor redColor],
        [UIColor orangeColor],
        [UIColor yellowColor],
    ]];
    
    dataSet.valueColors = @[
        [UIColor blueColor],
        [UIColor purpleColor],
        [UIColor systemPinkColor],
    ];
    
    [dataSets addObject:dataSet];
    }
    
    
    // 第三段
    
    
   
    
    LineChartData *chartData = [[LineChartData alloc] initWithDataSets:dataSets];
    self.chartView.data = chartData;
}

from charts.

myDonghao avatar myDonghao commented on June 27, 2024

我用了这样一个思路,效果勉勉强强,不知道能不能给你启发

from charts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.