7

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.

Nancy
  • 153
  • 1
  • 2
  • 6
  • what did u try? posting some source code will help. – Sunil Kumar Sahoo Jan 05 '12 at 06:57
  • AFAIK it doesn't support Background Image but you can set Color [like This](http://stackoverflow.com/questions/7711586/android-how-to-change-the-background-color-of-the-graph-using-achartengine) – MKJParekh Jan 05 '12 at 07:11

7 Answers7

14

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 :)

thanhbinh84
  • 17,876
  • 6
  • 62
  • 69
  • you set background image in your activity layout and set transparent color for your chart. Just follow my instruction. – thanhbinh84 Oct 22 '15 at 04:10
7

You just replace that code of line with this one:

mRenderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
Slavcho
  • 2,792
  • 3
  • 30
  • 48
  • Don't understand why the nicer Color.TRANSPARENT doesn't work for setMarginsColor, but this did it... thanks. – hotzen Sep 21 '14 at 21:27
4

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();
}
deepak Sharma
  • 1,641
  • 10
  • 23
3

Did you set your margincolor? Like this?

mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.RED);
mRenderer.setMarginsColor(Color.RED);

This will give a whole view of your graph background to red color

san
  • 1,845
  • 13
  • 23
1

For removing:

mRenderer.setMargins(new int[]{0,0,0,0});

And it will remove the margin :) its simple

For setting color:

mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.TRANSPARENT);
Umair
  • 1,206
  • 1
  • 13
  • 28
1

If you want to set transparent background color, you can try:

renderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));

It just be work for me!

1
mRenderer.setBackgroundColor(Color.Transparent);

And the Layout background where show the chart set your background image. Done.

kapex
  • 28,903
  • 6
  • 107
  • 121
Sherad
  • 55
  • 2
  • 7