Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart homescreen widget

is there any example, howto place any of charts in MPAndroidChart library to homescreen widget?

//i tried to use getChartbitmap(), but 1)bitmap is not created immediately after calling invalidate(), so it return null 2)i dont see way, howto initialize chart class without placing resources - which i cant do for widget.

anybody have some successful example ?

like image 251
Hynek Los kamute Avatar asked Oct 27 '25 03:10

Hynek Los kamute


1 Answers

Try this code

BarData chartData =...
BarChart chart = new BarChart(mContext);
chart.setData(chartData);

chart.measure(View.MeasureSpec.makeMeasureSpec(300,View.MeasureSpec.EXACTLY),
              View.MeasureSpec.makeMeasureSpec(500,View.MeasureSpec.EXACTLY));
chart.layout(0, 0, chart.getMeasuredWidth(), chart.getMeasuredHeight());

Bitmap chartBitmap = chart.getChartBitmap();
like image 180
Anatoliy Lukyanov Avatar answered Oct 28 '25 16:10

Anatoliy Lukyanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!