3

I'd like to save a full-sized image of my entire chart.

I usually show a maximum of 15 X values (barChartView.setVisibleXRange(minXRange: 3, maxXRange: 15)), so users must scroll to view all data.

I currently save the image like so:

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)

This works - the whole chart is saved as an image, however it seems to effectively be just a screenshot of the chart as it appears on my device (i.e. with a lot of data it seems pretty squashed up).

Is there a way to save a bigger image of the entire chart with all data (e.g. to emulate the size when 15 values are shown)?

  • You mentioning scrolling - is barChartView embedded in your own scroll view or is that scrolling functionality included in the Charts framework? – David Steppenbeck Sep 08 '19 at 12:02
  • It is included in the Charts framework. –  Sep 08 '19 at 12:12
  • Then it seems that you might have to access the view that is being scrolled around and take a snapshot of that, rather than snapshotting barChartView. If you look at barChartView subviews, can you find the scroll view in there? – David Steppenbeck Sep 08 '19 at 12:19
  • Unfortunately adding `print(barChartView.subviews)` to list the subviews just prints an empty array, and `barChartView.subviews.first` is nil. –  Sep 08 '19 at 12:25
  • no solution of this yet? I have exactly the same problem – rener172846 Sep 17 '20 at 18:34

0 Answers0