I am using MPandroidchart to display line charts in my application. I added the following code to show Marker View, but this isn not Show on
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); }
My CustomMarkerView Class
public class CustomMarkerView extends MarkerView { private TextView tvContent; public CustomMarkerView(Context context, int layoutResource) { super(context, layoutResource); tvContent = (TextView) findViewById(R.id.tvContent); }
}
Note. I use a snippet to display charts.
source share