2016-04-18 7 views
5

मैं MPandroidchart उपयोग कर रहा हूँ का उपयोग कर नहीं दिखा रहा है दृश्य मार्कर दिखाने के लिए कोड निम्नलिखित को शामिल किया है, लेकिन यहMarkerView मेरी application.I में लाइन चार्ट दिखाने के लिए MPAndroidChart

private void initializeChart(LineChart chart, String chartName) { 
    // Chart view 
    chart.setDrawGridBackground(false); 
    chart.setDescription(""); 
    chart.getLegend().setEnabled(true); 
    //chart.setTouchEnabled(false); 
    int color = getResources().getColor(R.color.white); 
    chart.getAxisLeft().setTextColor(color); // left y-axis 
    chart.getXAxis().setTextColor(color); 

    chart.setTouchEnabled(true); 
    CustomMarkerView mv = new CustomMarkerView(this.getActivity(), R.layout.marker_view_tv); 
    chart.setMarkerView(mv); 

    //X axis 
    XAxis xAxis = chart.getXAxis(); 
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); 
    xAxis.setDrawGridLines(false); 
    xAxis.setDrawLabels(true); 

    //Y axis 
    YAxis leftAxis = chart.getAxisLeft(); 
    YAxis rightAxis = chart.getAxisRight(); 
    rightAxis.setDrawLabels(false); 
    rightAxis.setDrawGridLines(false); 
    leftAxis.setDrawLabels(true); 
    leftAxis.setDrawGridLines(false); 
    leftAxis.setStartAtZero(false); 

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); 


    leftAxis.setLabelCount(Constants.KEY_LINE_YAXIS_SCALECOUNT, true); 
    ChartItem item = CannonJsonParser.parseCanonJson(act, act.res); 
    int maxYVal = pref.getInt(Constants.KEY_YAXIS_VALUE, 0); 
    leftAxis.setAxisMaxValue(maxYVal); 
    leftAxis.setAxisMinValue(0); 
    setLineData(item, chartName); 
    // set data 
    chart.setData(lineData); 

    chart.getLegend().setEnabled(false); 
    //animate 
    //chart.animateX(2000, Easing.EasingOption.EaseInExpo); 
    chart.setDragEnabled(true); 
    chart.setScaleXEnabled(true); 
    chart.setScaleYEnabled(false); 
    chart.setHighlightPerDragEnabled(false); 
    chart.setHighlightPerTapEnabled(false); 


} 

मेरे CustomMarkerView वर्ग

पर नहीं दिखा रहा है
public class CustomMarkerView extends MarkerView { 
private TextView tvContent; 

public CustomMarkerView(Context context, int layoutResource) { 
    super(context, layoutResource); 

    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) { 

    if (e instanceof CandleEntry) { 

     CandleEntry ce = (CandleEntry) e; 

     tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true)); 
    } else { 

     tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true)); 
    } 
} 

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

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

}

नोट: मैं टुकड़ा का उपयोग कर रहा चार्ट दिखाने के लिए।

उत्तर

4

आपका MarkerView दिखा रहा है क्योंकि आप पर प्रकाश डाला नहीं किया है आपके चार्ट में कोई प्रविष्टिMarkerView केवल उन प्रविष्टियों के लिए प्रदर्शित किया गया है जो हाइलाइट किए गए हैं। documentation में

chart.highlightValue(...)

कि पर अधिक:

जब से तुम नल प्रति प्रविष्टियों (chart.setHighlightPerTapEnabled(false) फोन करके) को उजागर करने कार्यक्षमता अक्षम है, आप केवल मूल्यों प्रोग्राम के रूप में हाइलाइट कर सकते हैं, इस तरह।

1

इस कोशिश, वर्ग

import android.content.Context; 
import android.widget.TextView; 

import com.github.mikephil.charting.components.MarkerView; 
import com.github.mikephil.charting.data.CandleEntry; 
import com.github.mikephil.charting.data.Entry; 
import com.github.mikephil.charting.utils.Utils; 

/** 
* Custom implementation of the MarkerView. 
* 
* @author Philipp Jahoda 
*/ 
public class MyMarkerView extends MarkerView { 

    private TextView tvContent; 

    public MyMarkerView(Context context, int layoutResource) { 
     super(context, layoutResource); 

     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, int dataSetIndex) { 

     if (e instanceof CandleEntry) { 

      CandleEntry ce = (CandleEntry) e; 

      tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true)); 
     } else { 

      tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true)); 
     } 
    } 

    @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(); 
    } 
} 

और टुकड़ा कक्षा में,

 MyMarkerView mv = new MyMarkerView(this.getActivity(), R.layout.custom_marker_view); 

     // set the marker to the chart 
     mChart.setMarkerView(mv); 

जोड़ सकते हैं आप के लिए यह उपयोगी ..

संबंधित मुद्दे