Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the background image for achartengine line chart in android?

I am using achartengine to dispaly the line chart in my application.I need to add the bg image for the chart , but when I set the bg image in xml , its not working. Have anyone tried this? Thanks in advance.

like image 384
Nancy Avatar asked Jan 05 '12 06:01

Nancy


3 Answers

Firstly, you need to add chart into your activity, and set preferred image as background in activity layout. (Take a look at XYChartBuilder in AChartEngineneDemo to see how to do that)

Secondly, set transparent background for chart and chart margin:

mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.TRANSPARENT);
mRenderer.setMarginsColor(getResources().getColor(R.color.transparent_background));

Finally, create your own transparent background since the Color.TRANSPARENT doesn't work for chart margin:

<color name="transparent_background">#00FF0000</color>

Hope this helps :)

like image 78
thanhbinh84 Avatar answered Oct 14 '22 19:10

thanhbinh84


You just replace that code of line with this one:

mRenderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
like image 38
Slavcho Avatar answered Oct 14 '22 19:10

Slavcho


This can be possible to set the background of line chart. it was a trick that works for me.

// RelativeLayout layout_ChartView = (RelativeLayout) findViewById(R.id.chart_View);  
private GraphicalView mChartView;  
if(mChartView==null){
mChartView.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
layout_ChartView.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT,300));  
mChartView = ChartFactory.getCubeLineChartView(this,mDataset,mRenderer, 0.2f);  
}
else{    
  mChartView.repaint();
}
like image 4
deepak Sharma Avatar answered Oct 14 '22 20:10

deepak Sharma