Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

big snap shot #2034

Closed
dimohamdy opened this issue Jan 4, 2017 · 5 comments
Closed

big snap shot #2034

dimohamdy opened this issue Jan 4, 2017 · 5 comments

Comments

@dimohamdy
Copy link

How can i get big snap shot for all data i show in chart ?

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 6, 2017

what you mean? a snapshot of the chart view? Use UIKit or CoreGraphics APIs can do so.
Charts has a API for this as well:
getChartImage is the func to save chart view as image. You can take a look at that too.

    /// Saves the current chart state with the given name to the given path on
    /// the sdcard leaving the path empty "" will put the saved file directly on
    /// the SD card chart is saved as a PNG image, example:
    /// saveToPath("myfilename", "foldername1/foldername2")
    ///
    /// - parameter to: path to the image to save
    /// - parameter format: the format to save
    /// - parameter compressionQuality: compression quality for lossless formats (JPEG)
    ///
    /// - returns: `true` if the image was saved successfully
    open func save(to path: String, format: ImageFormat, compressionQuality: Double) -> Bool
    {
		guard let image = getChartImage(transparent: format != .jpeg)
            else { return false }
        
        var imageData: Data!
        switch (format)
        {
        case .png:
            imageData = NSUIImagePNGRepresentation(image)
            break
            
        case .jpeg:
            imageData = NSUIImageJPEGRepresentation(image, CGFloat(compressionQuality))
            break
        }
        
        do
        {
            try imageData.write(to: URL(fileURLWithPath: path), options: .atomic)
        }
        catch
        {
            return false
        }
        
		return true
    }

@dimohamdy
Copy link
Author

I want to get image that show the total chart

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 10, 2017

Then the code I posted can do that.

getChartImage is the func to save chart view as image. You can take a look at that too.

@dimohamdy
Copy link
Author

i know but it take only the part of chart that shown in view not total chart

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 11, 2017

would you post a screenshot and your code to explain? I checked the code, it's supposed to render your chart view as image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants