2013-07-30 3 views
0

Je veux griller les valeurs sur les points de contact sur le LineGraph. Pour ce faire, j'ai essayé d'utiliser la méthode interne OnTouch() mais cela n'a pas fonctionné pour moi. Je ne sais pas comment commencer car je suis nouveau à achartengine. J'ai essayé ..Implémentation au toucher dans achartengine

public class DynamicGraphActivity extends Activity { 

private static GraphicalView view; 
private LineGraph line = new LineGraph(); 
private static Thread thread; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    thread = new Thread() { 
     public void run() 
     { 
      for (int i = 1; i < 31; i++) 
      { 

       Point p = MockData.getDataFromReceiver(i); // We got new data! 
       line.addNewPoints(p); // Add it to our graph 
       view.repaint(); 
      } 
     } 
    }; 
    thread.start(); 



} 
public boolean onTouch(View v, MotionEvent event) { 
    // TODO Auto-generated method stub 

    switch (event.getAction()) { 
    case MotionEvent.ACTION_MOVE: 
     displaycoordinates(event); 
     break; 

    case MotionEvent.ACTION_DOWN: 
     displaycoordinates(event); 
     break;     
    default: 
     break; 
    } 
    return true; 
}   

public void displaycoordinates(MotionEvent event) { 
    // TODO Auto-generated method stub 

    float x = event.getX(); 
    float y = event.getY(); 

    PointF point = new PointF(x,y); 

    NumberFormat nf = new DecimalFormat("#0.00"); 

    //Double j = getXval(x); 
    String xval = nf.format(x); 

    // Double k = point.getYvalue(y); 
    String yval = nf.format(y); 


    Toast toast = Toast.makeText(getApplicationContext(), xval+"xval"+yval+" yval", 0); 
    toast.show(); 


} 
@Override 
protected void onStart() { 
    super.onStart(); 
    view = line.getView(this); 
    setContentView(view); 
} 

}

Répondre

0

Je pense que vous avez commencé dans la mauvaise direction. Je vous suggère de jeter un oeil à this exemple afin de comprendre comment gérer les événements de clic sur le graphique et récupérer des informations sur le point le plus proche.