I did a bar chart with MPAndroidChart. I did a custom marker view class to view the values of the bar.
I would remove or hide the view after some seconds. It should work as a toast. But I cannot do it.
This is a problem first of all because after I touched the chart for the first time, it becomes visible and it disappears only if i find the right tapped condition.
There is someone who knows how solve this problem?
In my code I have:
mChart.invalidate();
mv = new CustomMarkerView(getContext(), R.layout.alert_chart, position, jsonResponse);
mChart.setMarker(mv);
And my CustomMarkerView is
public class CustomMarkerViewextends MarkerView {
public TextView correct;
public TextView wrong ;
public int position;
public JSONArray jsonArray;
public CustomMarkerView(Context context, int layoutResource, int pos, JSONArray json) {
super(context, layoutResource);
correct = (TextView) findViewById(R.id.correct);
wrong = (TextView) findViewById(R.id.wrong);
position = pos;
jsonArray = json;
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
switch (position){
case 1:
try {
correct.setText(getContext().getString(R.string.correct_alert) + " " + jsonArray.getJSONObject((int)(e.getX())).getString("TP"));
wrong.setText(getContext().getString(R.string.wrong_alert) + " " + jsonArray.getJSONObject((int)(e.getX())).getString("FP"));
} catch (JSONException e1) {
e1.printStackTrace();
} catch (ParseException e1) {
e1.printStackTrace();
}
break;
case 2:
try {
correct.setText(getContext().getString(R.string.tpr_alert) + " " + Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("TPR"))*100.0)/100.0);
wrong.setText(getContext().getString(R.string.msr_alert) + " " + Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("MSR"))*100.0)/100.0);
} catch (JSONException e1) {
e1.printStackTrace();
} catch (ParseException e1) {
e1.printStackTrace();
}
break;
case 3:
try {
correct.setText(getContext().getString(R.string.nmean_alert) + " " +Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("n_mean"))*100.0)/100.0);
wrong.setText(getContext().getString(R.string.nmax_alert) + " " +Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("n_max"))*100.0)/100.0);
} catch (JSONException e1) {
e1.printStackTrace();
} catch (ParseException e1) {
e1.printStackTrace();
}
break;
}
// this will perform necessary layouting
super.refreshContent(e, highlight);
}
private MPPointF mOffset;
@Override
public MPPointF getOffset() {
if(mOffset == null) {
// center the marker horizontally and vertically
mOffset = new MPPointF(-(getWidth()/2), -getHeight());
}
return mOffset;
}
}
I know, it's a bit late, but:
mChart.highlightValue(null);
Worked for me
Set an onTouchListener to your chart and in the MotionEvent ACTION_UP set the highlight value to null. Code :
chart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP: {
chart.highlightValue(null);
break;
}
}
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With