首页 > 解决方案 > iOS 图表 - 将完整图表另存为图像

问题描述

我想保存整个图表的全尺寸图像。

我通常最多显示 15 个 X 值 ( barChartView.setVisibleXRange(minXRange: 3, maxXRange: 15)),因此用户必须滚动才能查看所有数据。

我目前像这样保存图像:

let number = Double(chartValues.count)
barChartView.setVisibleXRange(minXRange: number, maxXRange: number) // Show full chart

barChartView.xAxis.labelRotationAngle = 90 // Rotate labels for image
barChartView.drawMarkers = false // Hide any shown markers
barChartView.highlightValues(nil) // Unhighlight all bars

barChartView.notifyDataSetChanged()

UIImageWriteToSavedPhotosAlbum(barChartView.getChartImage(transparent: false)!, nil, nil, nil)

这行得通——整个图表被保存为图像,但它似乎实际上只是图表的屏幕截图,因为它出现在我的设备上(即,有很多数据,它似乎被压扁了)。

有没有办法用所有数据保存整个图表的更大图像(例如,在显示 15 个值时模拟大小)?

标签: iosswiftios-charts

解决方案


推荐阅读