public Bitmap createGraphBitmap(List<BankModel> posts, Context context, int width, int height) { LineChart lineChart = new LineChart(context); lineChart.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); lineChart.setLayoutParams(new LinearLayout.LayoutParams(width, height)); GraphHelper.getInstance().styleLineChart(lineChart); GraphHelper.getInstance().formatChartDataNoThread(posts, lineChart, context); lineChart.measure( View.MeasureSpec.makeMeasureSpec( lineChart.getLayoutParams().width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec( lineChart.getLayoutParams().height, View.MeasureSpec.EXACTLY)); lineChart.layout(0, 0, lineChart.getMeasuredWidth(), lineChart.getMeasuredHeight()); Bitmap b = Bitmap.createBitmap(lineChart.getWidth(), lineChart.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); lineChart.draw(c); return b; }