2015-10-20 5 views
6

मैं MPAndroidChart को क्लिक करने के लिए केवल डेटा बिंदु के मान (लेबल) को प्रदर्शित करने के लिए एक तरीका ढूंढ रहा हूं। लेकिन ऐसा लगता है कि मुझे इसे दस्तावेज में भी ऑनलाइन नहीं मिला।टैप किए जाने पर मूल्य दिखाएं [एमपी एंड्रॉइड चार्ट]

मैंने line chart का उपयोग किया और जो भी मैं चाहता हूं केवल क्लिक करने पर निश्चित बिंदु के लेबल को प्रदर्शित करना है।

उत्तर

11

1- चार्ट में स्पर्श सक्षम

chart.setTouchEnabled(true); 

2 - MarkerView

public class CustomMarkerView extends MarkerView { 

    private TextView tvContent; 
    public CustomMarkerView (Context context, int layoutResource) { 
     super(context, layoutResource); 
     // this markerview only displays a textview 
     tvContent = (TextView) findViewById(R.id.tvContent); 
    } 

    // callbacks everytime the MarkerView is redrawn, can be used to update the 
    // content (user-interface) 
    @Override 
    public void refreshContent(Entry e, Highlight highlight) { 
     tvContent.setText("" + e.getVal()); // set the entry-value as the display text 
    } 

    @Override 
    public int getXOffset() { 
     // this will center the marker-view horizontally 
     return -(getWidth()/2); 
    } 

    @Override 
    public int getYOffset() { 
     // this will cause the marker-view to be above the selected value 
     return -getHeight(); 
    } 
} 

3 बनाएँ - tvContent दृश्य बनाएँ

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="40dp" 
    android:background="@drawable/markerImage" > 

    <TextView 
     android:id="@+id/tvContent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="7dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:text="" 
     android:textSize="12dp" 
     android:textColor="@android:color/white" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

</RelativeLayout> 

4. सेट चार्ट

CustomMarkerView mv = new CustomMarkerView (Context, R.layout.custom_marker_view_layout); 
chart.setMarkerView(mv); 

https://github.com/PhilJay/MPAndroidChart/wiki/MarkerView

में दृश्य मार्कर
संबंधित मुद्दे