Cómo añadir títulos de Axis a mpandroidchart

Estoy intentando agregar títulos del eje al gráfico de barras creado usando la biblioteca de la carta de mpandroid. Estoy utilizando más de un fragmento en mi actividad y el gráfico de barras es un fragmento. Estoy agregando datos dinámicamente y todo está funcionando bien. Quiero añadir títulos a los ejes x e y y cuando busqué encontré que no es compatible con la biblioteca. Sugieren que añada la vista de texto en el gráfico o edite la biblioteca.

Sé que este problema es el mismo que este post, pero no tienen la respuesta. Cómo agregar String Label a MPAndroidCharts

Intenté agregar un textview para ver y se agregó a la tapa del gráfico. He intentado dar layout_gravity pero no está funcionando. Cómo agregar la vista de texto a la parte inferior de la vista. También necesito agregar el título del eje de y también. Intenté agregar al contenedor y la visión también.

public class BarChartFragment extends Fragment { ScreenUtility screenUtility; BarChart bar; String nameOfChart,xAxisDesciption,yAxisDescription; TextView xAxisName; public BarChartFragment() { // Required empty public constructor } @Override public void onCreate(Bundle savedInstanceState) { //this.setRetainInstance(true); super.onCreate(savedInstanceState); if (getArguments() != null) { } } public View getView(){ return bar.getRootView(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { screenUtility = new ScreenUtility(getActivity()); ArrayList<BarEntry> entries = new ArrayList<>(); BarDataSet dataSet = new BarDataSet(entries,nameOfChart); dataSet.setColors(getColors()); dataSet.setStackLabels(new String[]{"CU1", "CU2"}); dataSet.setValueFormatter(new MyValueFormatter()); ArrayList<String> labels = new ArrayList<String>(); ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); dataSets.add(dataSet); bar = new BarChart(getActivity()); BarData data = new BarData(labels,dataSets); bar.setData(data); bar.setDrawValuesForWholeStack(true); bar.setDrawBarShadow(false); bar.setDrawValueAboveBar(false); bar.setHighlightEnabled(false); bar.setDrawGridBackground(false); bar.setDescription(""); XAxis x = bar.getXAxis(); x.setDrawGridLines(false); x.setPosition(XAxis.XAxisPosition.BOTTOM); YAxis yLabels = bar.getAxisLeft(); yLabels.setDrawGridLines(false); YAxis yLabels1 = bar.getAxisRight(); yLabels1.setEnabled(false); Legend legend = bar.getLegend(); legend.setPosition(Legend.LegendPosition.BELOW_CHART_RIGHT); bar.animateY(2000); int layoutHeight = screenUtility.getWidth() > screenUtility.getHeight() ? (int) screenUtility.getHeight() : (int) screenUtility.getWidth(); if(screenUtility.getHeight()>screenUtility.getWidth()) { ViewGroup.LayoutParams params = new ViewGroup.LayoutParams((int) screenUtility.getWidth() - 20, layoutHeight); bar.getRootView().setLayoutParams(new ViewGroup.LayoutParams(params)); }else{ ViewGroup.LayoutParams params = new ViewGroup.LayoutParams((int) (screenUtility.getWidth()/2) - 20, layoutHeight); bar.getRootView().setLayoutParams(new ViewGroup.LayoutParams(params)); } bar.setNoDataText("No Data is Available"); //Tried adding Textview Here xAxisName = new TextView(getActivity()); xAxisName.setText("Date"); xAxisName.setGravity(Gravity.BOTTOM); container.addView(xAxisName); return bar.getRootView(); } 

Introduzca aquí la descripción de la imagen

No puedo agregar el textview a la actividad porque todo se agrega dinámicamente y así que tengo que agregar el textview a cada gráfico. Cómo resolver esto y llevarlo al final del gráfico.

He encontrado la solución y la publicaré para futuras referencias para otras personas. Encontré el texto vertical desde el siguiente enlace.

Etiqueta vertical (girada) en Android

  xAxisName = new TextView(getActivity()); xAxisName.setText("Date"); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; params.setMargins(0, 0, 0, 20); VerticalTextView yAxisName = new VerticalTextView(getActivity(),null); yAxisName.setText("Yaxis Label"); FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); params2.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; container.addView(xAxisName, params); container.addView(yAxisName,params2); 

Sugiero que usted (use additionalTextViews fuera del gráfico) o modifique la biblioteca para su propósito.

Actualmente no se admite de forma predeterminada.

  • Cómo establecer el valor de incremento para el eje Y en MPAndroidChart
  • Implementar etiquetas de fecha y hora continuas en el eje x de mpandroidchart
  • MPAndroidChart - Diagrama de barras redondeado
  • Diferentes degradados y color para cada conjunto de líneas de datos
  • ¿Cómo no dibujar valores cero en un linechart mientras muestra sus valores de eje X en MPAndroidChart?
  • Eliminar etiquetas de puntos del gráfico de líneas mediante la biblioteca MPAndroidChart
  • Personalización de leyenda MPAndroidChart
  • Cómo ocultar los valores del eje x en Barchart de mpandroidChart
  • Cómo formatear valores dentro de MPAndroidChart?
  • ¿Cómo auto scroll MPAndroidChart gráfico de línea?
  • ¿Rellenar la escala Y específica con diverso color en carta de la línea usando la biblioteca de la carta del androide de MP?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.