weixin_39522103
weixin_39522103
2020-12-07 07:19

Support double X axes chart (支持双 X 轴图表)

该提问来源于开源项目:AAChartModel/AAChartKit-Swift

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39522103 weixin_39522103 5月前

    修改 AAChartType.bar 为 AAChartType.column,得到双X轴柱形图

    landscape

    image

    portrait

    image

    点赞 评论 复制链接分享
  • weixin_39522103 weixin_39522103 5月前

    The final chart (portrait)

    image

    点赞 评论 复制链接分享
  • weixin_39522103 weixin_39522103 5月前

    The final chart (landscape)

    image

    点赞 评论 复制链接分享
  • weixin_39522103 weixin_39522103 5月前

    Configure AAOptions instance object

    swift
    
    private func customDoubleXAxesChart() -> AAOptions {
            let gradientColorDic1 = AAGradientColor.linearGradient(
                direction: .toTop,
                startColor: "#7052f4",
                endColor: "#00b0ff"//颜色字符串设置支持十六进制类型和 rgba 类型
            )
    
            let gradientColorDic2 = AAGradientColor.linearGradient(
                direction: .toTop,
                startColor: "#EF71FF",
                endColor: "#4740C8"//颜色字符串设置支持十六进制类型和 rgba 类型
            )
    
            let aaChart = AAChart()
                .type(.bar)
    
            let aaTitle = AATitle()
                .text("2015 年德国人口金字塔")
                .style(AAStyle()
                    .color("#000000")
                    .fontSize(12.0))
    
            let aaCategories = ["0-4", "5-9", "10-14", "15-19",
            "20-24", "25-29", "30-34", "35-39", "40-44",
            "45-49", "50-54", "55-59", "60-64", "65-69",
            "70-74", "75-79", "80-84", "85-89", "90-94",
            "95-99", "100 + "]
    
            let aaXAxis1 = AAXAxis()
                .reversed(true)
                .categories(aaCategories)
                .labels(
                    AALabels()
                    .step(1))
    
            let aaXAxis2 = AAXAxis()
                .reversed(true)
                .opposite(true)
                .categories(aaCategories)
                .linkedTo(0)
                .labels(
                    AALabels()
                      .step(1))
    
            let aaYAxis = AAYAxis()
                .gridLineWidth(0)// Y 轴网格线宽度
                .title(
                    AATitle()
                    .text(""))//Y 轴标题
                .labels(
                    AALabels()
                    .formatter("""
    function () {
        return (Math.abs(this.value) / 1000000) + 'M';
    }
    """))
                .min( -4000000)
                .max( 4000000)
    
            let aaPlotOptions = AAPlotOptions()
                .series(
                    AASeries()
                    .animation(
                       AAAnimation()
                        .duration(800)
                        .easing(AAChartAnimationType.bounce.rawValue)
                    )
                    .stacking(AAChartStackingType.normal.rawValue))
    
            let aaTooltip = AATooltip()
                .enabled(true)
                .shared(false)
                .formatter("""
    function () {
        return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br>' +
            '人口: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0);
    }
    """)
    
            let aaSeriesElement1 = AASeriesElement()
                .name("Men")
                .color(gradientColorDic1)
                .data([-1746181, -1884428, -2089758, -2222362, -2537431, -2507081, -2443179,
                -2664537, -3556505, -3680231, -3143062, -2721122, -2229181, -2227768,
                -2176300, -1329968, -836804, -354784, -90569, -28367, -3878])
    
            let aaSeriesElement2 = AASeriesElement()
                .name("Women")
                .color(gradientColorDic2)
                .data([1656154, 1787564, 1981671, 2108575, 2403438, 2366003, 2301402, 2519874,
                3360596, 3493473, 3050775, 2759560, 2304444, 2426504, 2568938, 1785638,
                1447162, 1005011, 330870, 130632, 21208])
    
            let aaOptions = AAOptions()
                .chart(aaChart)
                .title(aaTitle)
                .xAxisArray([aaXAxis1,aaXAxis2])
                .yAxis(aaYAxis)
                .plotOptions(aaPlotOptions)
                .tooltip(aaTooltip)
                .series([aaSeriesElement1,aaSeriesElement2])
    
            return aaOptions
        }
    
    点赞 评论 复制链接分享

相关推荐