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

Unable to save the complete chart as image #4494

Open ravrocks opened 5 years ago

ravrocks commented 5 years ago

I have tried using chart.getBitmap() to get the drawable image and save it in gallery. But the bitmap im getting is only for current view of chart. Need help to save the complete chart(not the current view)!

jagadishnallappa commented 3 years ago

Hi,

I don't know if this answer will be bashed. But it worked for me. I just figured it out.

<HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true"
                android:scrollbars="horizontal">

                <LinearLayout
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:orientation="vertical" >

                    <com.github.mikephil.charting.charts.CombinedChart
                        android:id="@+id/combinedChartBroodingGrowing"
                        android:layout_width="3000dp"
                        android:layout_height="1000dp"
                        />
                </LinearLayout>
            </HorizontalScrollView>

Unfortunately you'll need to specify the layout_width and layout_height explicitly in order for this to work(You'll need to play around and decide what's best for you. Also, please note: I haven't checked for any side effects. Use with discretion. I'm so sorry!). Also make sure setVisibleXRangeMaximum is not set. And then call saveToGallery() as usual. You'll see the entire chart saved to gallery. :)