2011-10-10 16 views
10

Zaimplementowałem wykres liniowy za pomocą achartengine. Ale chcę zmienić kolor tła wykresu liniowego. Ktoś sugeruje poniższy kod do zmiany koloru tła.android - Jak zmienić kolor tła wykresu za pomocą achartengine

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

Ale to nie zmieni całego tła. Chcę zmienić całe tło, czy to możliwe? jeśli tak, to jak to zrobić proszę może ktoś pomóc me.The Poniższy obraz jest wyjście poprzedniego code.I chce zmienić cały bgcolor (czyli pozostała część czarnego do białego koloru również) Grpah without entire bgcolor

Alinegraph.java 

klasa publiczna ALinegraph rozszerza działanie {

/** Wywoływany, gdy aktywność jest tworzona po raz pierwszy. */

@Override 

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 

public class Linegraphpage rozciąga 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; 
    } 

} 

zaktualizowanego obrazu

enter image description here

+0

można opublikować zdjęcie po użyciu renderer.setBackgroundColor (Color.BLACK); – Sameer

+0

Aktualizuję obraz za pomocą kodu ur.But domyślny kolor jest z powrotem, więc chcę zmienić ten kolor na biały. Czy to możliwe? – naresh

+0

Wydaje mi się, że Twój problem został rozwiązany po zaakceptowaniu odpowiedzi. jakkolwiek myślę, że to powinno działać dla pełnego tła – Sameer

Odpowiedz

44

należy również ustawić margincolor:

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

to daje wgląd całokształtu swojej tle wykresu na czerwono.

+0

dziękuje, że działa, a co więcej, jak oddzielić etykiety osi Y i tekst (cena), podobnie jak oś X? Proszę odnieść się do dolnej krawędzi pytania. – naresh

+1

Myślę, że możesz użyć mRenderer.setMargins (new int [] {20, 30, 15, 0}); – Hanry

+0

proszę wyjaśnić ten kod? jakie są 4 wartości – naresh

Powiązane problemy