Search in sources :

Example 41 with Legend

use of com.github.mikephil.charting.components.Legend in project openScale by oliexdev.

the class StatisticsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    statisticsView = inflater.inflate(R.layout.fragment_statistics, container, false);
    txtGoalWeight = statisticsView.findViewById(R.id.txtGoalWeight);
    txtGoalWeight.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtGoalDiff = statisticsView.findViewById(R.id.txtGoalDiff);
    txtGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtGoalDayLeft = statisticsView.findViewById(R.id.txtGoalDayLeft);
    txtGoalDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtLabelGoalWeight = statisticsView.findViewById(R.id.txtLabelGoalWeight);
    txtLabelGoalWeight.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtLabelGoalDiff = statisticsView.findViewById(R.id.txtLabelGoalDiff);
    txtLabelGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtLabelDayLeft = statisticsView.findViewById(R.id.txtLabelDayLeft);
    txtLabelDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    viewMeasurementsStatistics = new ArrayList<>();
    viewMeasurementsStatistics.add(new WeightMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new WaterMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new MuscleMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new FatMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new BoneMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new BMIMeasurementView(statisticsView.getContext()));
    ArrayList<LegendEntry> legendEntriesWeek = new ArrayList<>();
    for (int i = 0; i < viewMeasurementsStatistics.size(); i++) {
        LegendEntry legendEntry = new LegendEntry();
        legendEntry.label = i + " - " + viewMeasurementsStatistics.get(i).getName().toString();
        legendEntriesWeek.add(legendEntry);
    }
    MarkerView mv = new ChartMarkerView(statisticsView.getContext(), R.layout.chart_markerview);
    radarChartWeek = statisticsView.findViewById(R.id.radarPastWeek);
    radarChartWeek.getXAxis().setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    radarChartWeek.getDescription().setEnabled(false);
    radarChartWeek.getYAxis().setEnabled(false);
    radarChartWeek.setExtraTopOffset(10);
    radarChartWeek.setRotationEnabled(false);
    Legend weekLegend = radarChartWeek.getLegend();
    weekLegend.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    weekLegend.setWordWrapEnabled(true);
    weekLegend.setExtra(legendEntriesWeek);
    weekLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    mv.setChartView(radarChartWeek);
    radarChartWeek.setMarker(mv);
    radarChartMonth = statisticsView.findViewById(R.id.radarPastMonth);
    radarChartMonth.getXAxis().setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    radarChartMonth.getDescription().setEnabled(false);
    radarChartMonth.getYAxis().setEnabled(false);
    radarChartMonth.setExtraTopOffset(10);
    radarChartMonth.setRotationEnabled(false);
    Legend monthLegend = radarChartMonth.getLegend();
    monthLegend.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    monthLegend.setWordWrapEnabled(true);
    monthLegend.setExtra(legendEntriesWeek);
    monthLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    mv.setChartView(radarChartMonth);
    radarChartMonth.setMarker(mv);
    OpenScale.getInstance().getScaleMeasurementsLiveData().observe(getViewLifecycleOwner(), new Observer<List<ScaleMeasurement>>() {

        @Override
        public void onChanged(List<ScaleMeasurement> scaleMeasurements) {
            updateOnView(scaleMeasurements);
        }
    });
    OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {

        @Override
        public void handleOnBackPressed() {
            requireActivity().finish();
        }
    };
    requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), onBackPressedCallback);
    return statisticsView;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) BoneMeasurementView(com.health.openscale.gui.measurement.BoneMeasurementView) ArrayList(java.util.ArrayList) ChartMarkerView(com.health.openscale.gui.measurement.ChartMarkerView) WeightMeasurementView(com.health.openscale.gui.measurement.WeightMeasurementView) BMIMeasurementView(com.health.openscale.gui.measurement.BMIMeasurementView) WaterMeasurementView(com.health.openscale.gui.measurement.WaterMeasurementView) ChartMarkerView(com.health.openscale.gui.measurement.ChartMarkerView) MarkerView(com.github.mikephil.charting.components.MarkerView) FatMeasurementView(com.health.openscale.gui.measurement.FatMeasurementView) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) MuscleMeasurementView(com.health.openscale.gui.measurement.MuscleMeasurementView) LegendEntry(com.github.mikephil.charting.components.LegendEntry) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Legend (com.github.mikephil.charting.components.Legend)41 XAxis (com.github.mikephil.charting.components.XAxis)24 YAxis (com.github.mikephil.charting.components.YAxis)22 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)7 Typeface (android.graphics.Typeface)6 AxisBase (com.github.mikephil.charting.components.AxisBase)6 View (android.view.View)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 ArrayList (java.util.ArrayList)5 Paint (android.graphics.Paint)3 MarkerView (com.github.mikephil.charting.components.MarkerView)3 LineData (com.github.mikephil.charting.data.LineData)3 LineDataSet (com.github.mikephil.charting.data.LineDataSet)3 LegendEntry (com.github.mikephil.charting.components.LegendEntry)2 Entry (com.github.mikephil.charting.data.Entry)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 RadarMarkerView (com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView)2 DecimalFormat (java.text.DecimalFormat)2 List (java.util.List)2 ValueAnimator (android.animation.ValueAnimator)1