AAChartKit-Swift icon indicating copy to clipboard operation
AAChartKit-Swift copied to clipboard

折线图左右显示不完整

Open auqarius opened this issue 1 year ago • 5 comments

我在使用的时候发现 chartView 宽度设定值很小的时候,折线图会被截取,表现如下:

正常情况,宽度 400,左右就是有圆角的 IMG_7622

出错情况,宽度 200,左右就被截取了 IMG_7623

代码如下

aaChartView!.frame = CGRect(x: 0,y: 60,width: 200,height: 130)  // height 设定的大小不影响是否截取,但是 width 设定过小就会被截取,如果是 400 就不会被截取
        view.addSubview(aaChartView!)
        aaChartView!.isScrollEnabled = false//Disable chart content scrolling
        aaChartView!.isClearBackgroundColor = true
        aaChartView!.delegate = self as AAChartViewDelegate

        aaChartModel = AAChartModel()
            .chartType(.line)
            .xAxisTickInterval(20)   /// 尝试用这个值去解决问题也没法解决
            .animationType(.easeInOutCubic)
            .dataLabelsEnabled(false)
            .markerRadius(0)
            .colorsTheme([])
            .tooltipEnabled(false)
            .legendEnabled(false)
            .xAxisVisible(false)
            .yAxisVisible(false)
            .yAxisMin(-1)
            .series([
                AASeriesElement()
                    .name("Name")
                    .data([0,0,0,1,5,10,3])
                    .lineWidth(6)
                    .color("#ffffff")
            ])
        aaChartView!.aa_drawChartWithChartModel(aaChartModel!)

有没有什么方法解决呢?

auqarius avatar Oct 17 '24 15:10 auqarius

经过再次测试,发现与 lineWidth 有关系,lineWidth 设定为 10,那即使把 chatView.width 设定为 400,也会被截取。

截屏 2024-10-17 23 19 09

auqarius avatar Oct 17 '24 15:10 auqarius

试试调整一下 AAChartModelmargin 值:

    public var margin: [Any?]?

AAChartModel avatar Oct 18 '24 01:10 AAChartModel

或者试试调整一下 AAChartmargin 或者 marginRight 属性值:

    public var margin: [Any?]? //Margin between the outer edge of the chart and the drawing area. The numbers in the array represent the top, right, bottom, and left ([👆, 👉, 👇, 👈]). You can also use marginTop, marginRight, marginBottom, and marginLeft to set the margins in a certain direction. Defaults to [null]
    public var marginTop: Float? //👆
    public var marginRight: Float? //👉
    public var marginBottom: Float? //👇
    public var marginLeft: Float? //👈

AAChartModel avatar Oct 18 '24 01:10 AAChartModel

或者试试调整一下 AAChartspacing 或者 spacingRight 属性值:

    public var spacing: [Float]? //The distance between the outer edge of the chart and the content, like title or legend, or axis title and labels if present. The numbers in the array designate top, right, bottom and left ([👆, 👉, 👇, 👈]) respectively. Use the options spacingTop, spacingRight, spacingBottom and spacingLeft options for shorthand setting of one option. Defaults to [10, 10, 15, 10].
    public var spacingTop: Float? //👆
    public var spacingRight: Float? //👉
    public var spacingBottom: Float? //👇
    public var spacingLeft: Float? //👈

AAChartModel avatar Oct 18 '24 01:10 AAChartModel

参考在线文档:

  • https://api.highcharts.com/highcharts/chart.marginRight
  • https://api.highcharts.com/highcharts/chart.spacingRight

AAChartModel avatar Oct 18 '24 01:10 AAChartModel

我测试了一下, 发现似乎和这个:

  • https://github.com/AAChartModel/AAChartKit/issues/1571

是同一个问题.

AAChartModel avatar Oct 18 '24 02:10 AAChartModel

参考此次提交的内容:

  • https://github.com/AAChartModel/AAChartKit-Swift/commit/bbdd661b7c7661c45d73df55d81d3c1247210229

AASeriesElement 配置 clip 属性为 false 即可.

AAChartModel avatar Oct 18 '24 02:10 AAChartModel

更新 AAInfographics 至最新内容即可使用新增的 clip 属性.

  • #359

AAChartModel avatar Oct 18 '24 02:10 AAChartModel

配置好后的显示如下:

截屏2024-10-18 10 56 00

AAChartModel avatar Oct 18 '24 02:10 AAChartModel

如同这个问题:

  • https://github.com/AAChartModel/AAChartKit/issues/1571

clip 属性生效有延迟, 暂未找到解决方案.

AAChartModel avatar Oct 18 '24 03:10 AAChartModel

感谢,测试发现确实可以解决截取问题。但延迟也确实存在,希望早日解决延迟问题。

auqarius avatar Oct 18 '24 03:10 auqarius