AAChartModel / AAChartKit

📈📊🚀🚀🚀An elegant modern declarative data visualization chart framework for iOS, iPadOS and macOS. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types. 极其精美而又强大的现代化声明式数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
https://cocoapods.org/pods/AAChartKit
MIT License
4.71k stars 751 forks source link

请问单个区域的渐变可以实现吗? #1459

Closed wangfang871111 closed 1 year ago

wangfang871111 commented 1 year ago

您好,请问这种单个区域的渐变色可以实现吗?不胜感激

AAChartModel commented 1 year ago

支持, 参考相同问题:

AAChartModel commented 1 year ago

OC版本的配置方式如下:

- (AAChartModel *)customAreasplineChartWithColorfulGradientColorZones {
    NSArray *redStopsArr = @[
        @[@0.0, AARgbaColor(255, 0, 0, 1.0)],//颜色字符串设置支持十六进制类型和 rgba 类型
        @[@1.0, AAColor.clearColor]
    ];

    NSArray *greenStopsArr = @[
        @[@0.0, AARgbaColor(0, 255, 0, 1.0)],//颜色字符串设置支持十六进制类型和 rgba 类型
        @[@1.0, AAColor.clearColor]
    ];

    NSArray *blueStopsArr = @[
        @[@0.0, AARgbaColor(0, 0, 255, 1.0)],//颜色字符串设置支持十六进制类型和 rgba 类型
        @[@1.0, AAColor.clearColor]
    ];

    NSDictionary *redGradientColorDic = [AAGradientColor gradientColorWithDirection:AALinearGradientDirectionToBottom stopsArray:redStopsArr];
    NSDictionary *greenGradientColorDic = [AAGradientColor gradientColorWithDirection:AALinearGradientDirectionToBottom stopsArray:greenStopsArr];
    NSDictionary *blueGradientColorDic = [AAGradientColor gradientColorWithDirection:AALinearGradientDirectionToBottom stopsArray:blueStopsArr];

    AADataElement *singleSpecialData = AADataElement.new
        .markerSet(AAMarker.new
                   .radiusSet(@8)//曲线连接点半径
                   .symbolSet(AAChartSymbolTypeCircle)//曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle"
                   .fillColorSet(AAColor.whiteColor)//点的填充色(用来设置折线连接点的填充色)
                   .lineWidthSet(@5)//外沿线的宽度(用来设置折线连接点的轮廓描边的宽度)
                   //外沿线的颜色(用来设置折线连接点的轮廓描边颜色,当值为空字符串时,默认取数据点或数据列的颜色)
                   .lineColorSet(@"#1E90FF")//道奇蓝
                   )
        .dataLabelsSet(AADataLabels.new
                       .enabledSet(true)
                       .allowOverlapSet(true)
                       .useHTMLSet(true)
                       .backgroundColorSet(AARgbaColor(65, 111, 166, 1.0))
                       .borderRadiusSet(@10)
                       .shapeSet(@"callout")
                       .formatSet(@"{point.category}<br>{series.name}: {point.y} %")
                       .styleSet(AAStyleColorSizeWeight(AAColor.whiteColor, 12, AAChartFontWeightTypeBold))
                       .xSet(@-80).ySet(@(5))
                       .alignSet(AAChartAlignTypeCenter)
                       .verticalAlignSet(AAChartVerticalAlignTypeTop)
                       .overflowSet(@"none")
                       .cropSet(false)
                       )
        .ySet(@85.3);

    AAStyle *axisLabelsStyle = AAStyleColorSizeWeight(AAColor.whiteColor, 12, AAChartFontWeightTypeBold);

    return AAChartModel.new
        .chartTypeSet(AAChartTypeAreaspline)
        .backgroundColorSet(AAColor.blackColor)
        .categoriesSet(@[
            @"Jan", @"Feb", @"Mar", @"Apr", @"May", @"Jun",
            @"Jul", @"Aug", @"Sep", @"Oct", @"Nov", @"Dec"
        ])
        .dataLabelsEnabledSet(false)
        .legendEnabledSet(false)
        .markerRadiusSet(@0)
        .xAxisLabelsStyleSet(axisLabelsStyle)
        .yAxisLabelsStyleSet(axisLabelsStyle)
        .xAxisGridLineStyleSet([AALineStyle styleWithColor:AAColor.whiteColor dashStyle:AAChartLineDashStyleTypeLongDashDotDot width:@0.5])
        .yAxisGridLineStyleSet([AALineStyle styleWithWidth:@0])
        .seriesSet(@[
            AASeriesElement.new
                .nameSet(@"空气湿度")
                .lineWidthSet(@6)
                .zoneAxisSet(@"x")
                .zonesSet(@[
                    AAZonesElement.new
                        .valueSet(@2)
                        .colorSet(AAColor.redColor)
                        .fillColorSet((id)redGradientColorDic ),
                    AAZonesElement.new
                        .valueSet(@5)
                        .colorSet(AAColor.greenColor)
                        .fillColorSet((id)greenGradientColorDic),
                    AAZonesElement.new
                        .colorSet(AAColor.blueColor)
                        .fillColorSet((id)blueGradientColorDic),
                ])
                .dataSet(@[@56.5, @33.3, @85.3, @23.9, @29.6, @34.5, @28.2, @26.5, @15.2, @56.5, @33.3, singleSpecialData]),
        ]);
}

AAChartKit 的 demo 中有此示例, 下载运行查看即可.