PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.53k stars 9.01k forks source link

feature request: Exporting svg from chart #3367

Open prompteus opened 7 years ago

prompteus commented 7 years ago

I'm aware of saveToGallery, saveToPath and getDrawBitmap methods, but a vector-based format like svg would be nice.

jhannink commented 4 years ago

@PhilJay Any update on this? This would be an incredibly useful feature, e.g. for including the plots from screen in generated pdf reports.

jhannink commented 4 years ago

Just in case someone else is looking for solution to a similar problem, I found a work-around. Using android.graphics.pdf, one can store the chart view as a vector-based format in pdf with

fun printView2PDF(content: View, outFile:File){
        // create a new document
        val document = PdfDocument();

        // crate a page description
        val pageInfo = PdfDocument.PageInfo.Builder(
            content.measuredWidth, content.measuredHeight,1)
            .create();

        // start a page
        val page = document.startPage(pageInfo);

        // draw something on the page
        content.draw(page.getCanvas());

        // finish the page
        document.finishPage(page);
        document.writeTo(FileOutputStream(outFile));
        // close the document
        document.close();
    }