2013-06-05 8 views
5
aktualisiert

Ich machte ein Diagramm von meiner Datenbank mit androidplot, aber wenn ich die Datenbank mit Knopf zurückstellte, aktualisiert das Diagramm dosnt, wie aktualisiere ich das Diagramm, ohne die Tätigkeit neu zu bilden?wie man Diagramm in androidplot

public class Overview extends Activity { 
Number[] seriesOfNumbers; 
private XYPlot mySimpleXYPlot; 
// double totalprofitd; 
private BetsDbAdapter dbHelper; 
TextView NBtext; 
TextView TOtext; 
TextView TPtext; 
TextView ROItext; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.c_overview); 

    dbHelper = new BetsDbAdapter(this); 
    TOtext = (TextView) findViewById(R.id.turnover); 
    TPtext = (TextView) findViewById(R.id.totalprofit); 
    NBtext = (TextView) findViewById(R.id.numberOfBet); 
    ROItext = (TextView) findViewById(R.id.roi); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.android_tab_layout, menu); 
    return true; 
} 

public void resetClick(View v) { 
    dbHelper.open(); 
    dbHelper.deleteDatabase(); 
    dbHelper.close(); 
    CalculateProfit(); 
    graph(); 
} 

@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 
    CalculateProfit(); 
    graph(); 
} 

public void CalculateProfit() { 
    dbHelper.open(); 
    List<String> tip = dbHelper.getTip(); 
    List<String> betamount = dbHelper.getBetAmount(); 
    ArrayList<String> sbodds = dbHelper.getSBodds(); 
    dbHelper.close(); 

    int NumberOfBets = tip.size(); 
    double turnover = 0; 
    double ROI = 0; 
    double totalprofit = 0; 
    double profit = 0; 
    seriesOfNumbers = new Number[NumberOfBets]; 
    for (int i = 0; i < NumberOfBets; i++) { 
     String WLV = tip.get(i); 
     String arrpct[] = WLV.split(" ", 2); 
     String WLV1 = arrpct[0]; 

     if (WLV1.equals("W")) { 
      profit = Double.parseDouble(betamount.get(i).replaceAll(",", 
        ".")) 
        * (Double.parseDouble(sbodds.get(i)) - 1); 
     } 

     else if (WLV1.equals("L")) { 
      profit = -Double.parseDouble(betamount.get(i).replaceAll(",", 
        ".")); 
     } else { 
      profit = 0; 
     } 
     //Add total turnover 
     turnover += Double.parseDouble(betamount.get(i).replaceAll(",", ".")); 
     //Add total profit 
     totalprofit += profit; 
     //For the graph 
     seriesOfNumbers[i] = totalprofit; 
    } 
    ROI = ((turnover + totalprofit)/turnover) * 100; 
    TPtext.setText(new DecimalFormat("##.##").format(totalprofit)); 
    TOtext.setText(new DecimalFormat("##.##").format(turnover)); 
    NBtext.setText(Integer.toString(NumberOfBets)); 
    ROItext.setText(new DecimalFormat("##.##").format(ROI)); 
} 

public void graph() { 
    dbHelper.open(); 
    // initialize our XYPlot reference: 
    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); 

    // Turn the above arrays into XYSeries': 
    XYSeries series1 = new SimpleXYSeries(Arrays.asList(seriesOfNumbers), 
    // SimpleXYSeries takes a List so turn our array into a list 
      SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, 
      // Y_VALS_ONLY means use the element index as the x value 
      "Series1"); // Set the display title of the series 

    // Create a formatter to use for drawing a series using 
    // LineAndPointRenderer: 
    LineAndPointFormatter series1Format = new LineAndPointFormatter(
      Color.rgb(0, 200, 0), // line color 
      null, // point color 
      Color.rgb(0, 200, 0)); // fill color (none) 

    // add a new series' to the xyplot: 
    mySimpleXYPlot.addSeries(series1, series1Format); 

    // reduce the number of range labels 
    mySimpleXYPlot.setTicksPerRangeLabel(3); 

    // by default, AndroidPlot displays developer guides to aid in laying 
    // out your plot. 
    // To get rid of them call disableAllMarkup(): 
    mySimpleXYPlot.disableAllMarkup(); 
    dbHelper.close(); 
} 

}

Dont kennen sein, wenn wichtige, aber hier ist meine:

c_overview.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/Profit_text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:ems="6" 
       android:text="Profit:" /> 

      <TextView 
       android:id="@+id/ROI_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:ems="6" 
       android:text="ROI:" /> 

      <TextView 
       android:id="@+id/Bet_Counter_text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:ems="6" 
       android:text="No. of Bets:" /> 

      <TextView 
       android:id="@+id/Turnover_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:ems="6" 
       android:text="Turnover:" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="130dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.75" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/totalprofit" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:ems="10" 
       android:text="total profit" /> 

      <TextView 
       android:id="@+id/roi" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:ems="10" 
       android:text="Return Of Interest" /> 

      <TextView 
       android:id="@+id/numberOfBet" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="number of bets" /> 

      <TextView 
       android:id="@+id/turnover" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:ems="10" 
       android:text="Turnover" /> 
     </LinearLayout> 

     <Button 
      android:id="@+id/reset" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:onClick="resetClick" 
      android:text="Reset" /> 

    </LinearLayout> 

    <com.androidplot.xy.XYPlot 
      android:id="@+id/mySimpleXYPlot" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginTop="10px" 
      android:layout_marginLeft="10px" 
      android:layout_marginRight="10px" 
      title="A Simple XYPlot Example"/> 



</LinearLayout> 

Antwort

13

I 2 nutzbare Funktionen gefunden: klar und neu zu zeichnen, seine so jetzt arbeiten:

CalculateProfit(); 
mySimpleXYPlot.clear(); 
graph();   
mySimpleXYPlot.redraw(); 
0

Android Chart mit AndroidPlot Tutorial

In diesem Android Chart mit AndroidPlot Tutorial lernen wir, wie man ein Diagramm in einer Android App mit AndroidPlot Bibliothek erstellt. Das Erstellen eines Diagramms in Android wird durch AndroidPlot vereinfacht, wir müssen nur über einige Klassen wissen. Wie man Werte zu diesen Klassen übergeben Sie das Diagramm zeichnen und dann, wie ...

Lesen Sie mehr: http://latest-tutorial.com/2014/03/12/android-chart-using-androidplot-tutorial/

0

Vor u der Graph nur die folgende Funktion plot.clear verwenden starten Plotten(); Und entfernen Sie auch die Serie plot.removeSeries (xLabels [i]); Dabei steht xLabels für den x-Achsenwert

Verwandte Themen