MPAndroidChart Desktop Widget

is there any example how to place any charts in the MPAndroidChart library for desktop widgets?

// I tried to use getChartbitmap (), but 1) the bitmap is not created immediately after calling invalidate (), so it returns null 2) I don't see a way how to initialize the chart class without allocating resources - which I cannot do for the widget.

Does anyone have a successful example?

+3


source to share


3 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();

      

+3


source


It Bitmap

takes a few milliseconds to draw content on the chart. This is why a call getChartBitmap()

immediately after invalidate()

will not return a valid one Bitmap

.



Try to use Handler

and delay the time until extracting Bitmap

100ms abundance.

+1


source


In a chart operation, the getChartBitmap () function works fine! It returns a bitmap without any error. IMHO, what a problem, the widget has no activity, the placement of the created chart in the layout does not take effect :( So we cannot have a widget with this chart at all, and this is very sad - this chart is so really cool.

-1


source







All Articles