机器人 - 如何改变图形使用achartengine的背景颜色机器人、图形、颜色、背景

2023-09-06 01:25:55 作者:眉间万般柔情

我实现了使用achartengine线图。但我想改变线图的背景色。有人建议下列code代表改变背景颜色。

I implemented the Line graph using the achartengine. But i want change the line graph background color. Somebody suggest that the following code for changing the background color.

mRenderer.setApplyBackgroundColor(真正的); mRenderer.setBackgroundColor(Color.RED);

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

但它不会改变整个背景。我想改变整个背景是这可能吗?如果是的话,那该怎么办呢,请任何人可以帮助me.The下面的图片是的previous codeI输出要改变整个BGCOLOR(指剩余的黑色部分为白色也)

But it will not change the entire background. I want to change the entire background is it possible? if yes, then how to do it please can anybody help me.The following image is the output of the previous code.I want to change the entire bgcolor(means remaining black color part to white also)

Alinegraph.java

公共类ALinegraph扩展活动 {

public class ALinegraph extends Activity {

/ **第一次创建活动时调用。 * /

/** Called when the activity is first created. */

@Override

公共无效的onCreate(包savedInstanceState)

public void onCreate(Bundle savedInstanceState)

{

    super.onCreate(savedInstanceState);      
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);   
    setContentView(R.layout.main);

    Button Linegraph = (Button) findViewById(R.id.Linegraph);
    Linegraph.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
              Linegraphpage ACTC = new Linegraphpage();
              Intent intent = ACTC.execute(ALinegraph.this);
              startActivity(intent);                  
        }});           
}

}

Linegraphpage.java

公共类Linegraphpage扩展AbstractDemoChart

public class Linegraphpage extends AbstractDemoChart

{

  /**
   * Returns the chart name.
   * 
   * @return the chart name
   */
  public String getName() {
    return "Average temperature";
  }

  /**
   * Returns the chart description.
   * 
   * @return the chart description
   */
  public String getDesc() {
    return "The average temperature in 4 Greek islands (line chart)";
  }

  /**
   * Executes the chart demo.
   * 
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context) {
    String[] titles = new String[] { "Crete","Corfu"};
    List<double[]> x = new ArrayList<double[]>();
    for (int i = 0; i < titles.length; i++) {
      x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
    }
    List<double[]> values = new ArrayList<double[]>();
    values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3 });
    values.add(new double[] { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 });

    int[] colors = new int[] { Color.CYAN,Color.GREEN};
    PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE,PointStyle.POINT};
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    int length = renderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) {
      ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    }
    setChartSettings(renderer, "", "", "price", 0, 12, 0, 190,
        Color.GREEN, Color.GREEN);
    renderer.setXLabels(10);
    renderer.setYLabels(7);    
    renderer.setShowGrid(false);
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.RIGHT);
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.WHITE);
    renderer.setZoomButtonsVisible(true);
    renderer.setPanLimits(new double[] { -10, 20, -10, 40 });
    renderer.setZoomLimits(new double[] { -10, 20, -10, 40 });

    Intent intent = ChartFactory.getLineChartIntent(context, buildDataset(titles, x, values),
        renderer, "");
    return intent;
  }

}

更新后的图像的

Updated image

推荐答案

您也可以设置你margincolor:

you should also set your margincolor:

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

这会给你的图形背景为红色的整体视图。

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