How to set a background image for an akhartana diagram chart in android?

I use achartengine to display a line chart in my application. I need to add a bg image for the chart, but when I installed the bg image in xml, it does not work. Has anyone tried this? Thanks in advance.

+7
source share
7 answers

First, you need to add a diagram to your activity and set your preferred image as a background in the action layout. (Take a look at XYChartBuilder at AChartEngineneDemo to see how to do this)

Secondly, set a transparent background for the chart and chart fields:

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

Finally, create your own transparent background, as Color.TRANSPARENT does not work for the chart field:

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

Hope this helps :)

+14
source

You simply replace this line code with this:

 mRenderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01)); 
+7
source

Have you set your Marxine color? Like this?

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

This will give a complete picture of your graph with red color.

+3
source

It may be possible to set the line chart background. 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(); } 
+3
source
 mRenderer.setBackgroundColor(Color.Transparent); 

And the background of the layout in which the chart is displayed sets the background image. Done.

+1
source

For removing:

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

And he will delete the field :) its simple

To set the color:

 mRenderer.setApplyBackgroundColor(true); mRenderer.setBackgroundColor(Color.TRANSPARENT); 
+1
source

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

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

This is just a job for me!

+1
source

All Articles