I want to show xaxis value in line chart. for example if a line one is clicked then it need to show line1 in markerview .I attach my code in below:
String[] xAxis= {"Line1","Line2","Line3","Line4"}
lineChart.setPinchZoom(false);
lineChart.setDrawGridBackground(false);
lineChart.getDescription().setText("");
lineChart.setScaleEnabled(false);
XAxis xAxis = lineChart.getXAxis();
xAxis.setTextColor(Color.parseColor("#ef9a9a"));
xAxis.setValueFormatter(new IndexAxisValueFormatter(xValues));
xAxis.setEnabled(true);
xAxis.setGranularity(1f);
xAxis.setDrawGridLines(false);
xAxis.setGranularityEnabled(true);
xAxis.setAvoidFirstLastClipping(false);
xAxis.setDrawAxisLine(true);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(8);
YAxis yAxisRight = lineChart.getAxisRight();
yAxisRight.setDrawLabels(false);
Legend legend = lineChart.getLegend();
legend.setEnabled(true);
CustomMarker cm = new CustomMarker(context, R.layout.custom_marker_view);
cm.setChartView(lineChart);
lineChart.setMarker(cm);
lineChart.setVisibleXRangeMaximum(7);
lineChart.moveViewToX(1);
lineChart.invalidate();
//Markerclass:
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(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();
}
}
here I dnt know how to pass my Xaxis value in theis line
tvContent.setText("" + e.getVal());//to show the particular x axis value if line one is clicked then it want to show line1
question from:
https://stackoverflow.com/questions/66057525/mpandroidchart-display-markerview-of-xaxis-value-when-a-xaxis-value-is-clicked 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…