Java Code Examples for com.github.mikephil.charting.components.Legend#setTextColor()

The following examples show how to use com.github.mikephil.charting.components.Legend#setTextColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void initBar() {
    BarChart barChart = getBarChart();
    if(barChart == null) {
        return;
    }
    barChart.setDescription("");

    barChart.setDrawGridBackground(false);

    barChart.setMaxVisibleValueCount(200);

    Legend l = barChart.getLegend();
    l.setPosition(Legend.LegendPosition.ABOVE_CHART_LEFT);
    l.setTextColor(Color.WHITE);

    YAxis yl = barChart.getAxisLeft();
    yl.setTextColor(Color.WHITE);
    yl.setGridColor(Color.WHITE);
    barChart.getAxisRight().setEnabled(false);

    XAxis xl = barChart.getXAxis();
    xl.setDrawGridLines(false);
    xl.setTextColor(Color.WHITE);
    xl.setGridColor(Color.WHITE);
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setDrawAxisLine(true);
    xl.setLabelRotationAngle(-90);
    xl.setDrawLabels(true);
    xl.setLabelsToSkip(0);
}
 
Example 2
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void initScatter() {
    final ScatterChart scatterChart = getScatterChart();
    if(scatterChart == null) {
        return;
    }
    scatterChart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Show
            AlertDialog.Builder builder = new AlertDialog.Builder(CalibrationLinearityActivity.this);
            builder.setTitle(CalibrationLinearityActivity.this.getText(R.string.calibration_select_frequency));
            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(CalibrationLinearityActivity.this,
                    R.array.calibrate_type_list_array, android.R.layout.simple_selectable_list_item);
            builder.setAdapter(adapter,
                    new ItemActionOnClickListener(CalibrationLinearityActivity.this, scatterChart));
            builder.show();
        }
    });

    scatterChart.setDescription("");

    scatterChart.setDrawGridBackground(false);

    scatterChart.setMaxVisibleValueCount(200);

    Legend l = scatterChart.getLegend();
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    l.setTextColor(Color.WHITE);

    YAxis yl = scatterChart.getAxisLeft();
    yl.setTextColor(Color.WHITE);
    yl.setGridColor(Color.WHITE);
    scatterChart.getAxisRight().setEnabled(false);

    XAxis xl = scatterChart.getXAxis();
    xl.setDrawGridLines(false);
    xl.setTextColor(Color.WHITE);
    xl.setGridColor(Color.WHITE);
}
 
Example 3
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void initLine() {
    LineChart lineChart = getLineChart();
    if(lineChart == null) {
        return;
    }
    lineChart.setDescription("");

    lineChart.setDrawGridBackground(false);

    // enable scaling and dragging

    Legend l = lineChart.getLegend();
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    l.setTextColor(Color.WHITE);

    YAxis yl = lineChart.getAxisLeft();
    yl.setTextColor(Color.WHITE);
    yl.setGridColor(Color.WHITE);
    lineChart.getAxisRight().setEnabled(false);

    XAxis xl = lineChart.getXAxis();
    xl.setDrawGridLines(false);
    xl.setTextColor(Color.WHITE);
    xl.setGridColor(Color.WHITE);
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setDrawAxisLine(true);
    xl.setLabelRotationAngle(-90);
    xl.setDrawLabels(true);
    xl.setLabelsToSkip(0);
}
 
Example 4
Source File: Utils.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
public static void setupChart(@NonNull LineChart chart, boolean small, @ColorRes @Nullable Integer fgColorRes) {
    chart.clear();

    int fgColor;
    Context context = chart.getContext();
    if (fgColorRes == null)
        fgColor = CommonUtils.resolveAttrAsColor(context, R.attr.colorOnSurface);
    else
        fgColor = ContextCompat.getColor(context, fgColorRes);

    chart.setDescription(null);
    chart.setDrawGridBackground(false);
    chart.setBackgroundColor(Color.alpha(0));
    chart.setTouchEnabled(false);

    Legend legend = chart.getLegend();
    legend.setTextColor(fgColor);
    legend.setEnabled(true);

    LineData data = new LineData();
    data.setValueTextColor(fgColor);
    chart.setData(data);

    YAxis ya = chart.getAxisLeft();
    ya.setAxisLineColor(fgColor);
    ya.setTextColor(fgColor);
    ya.setTextSize(small ? 8 : 9);
    ya.setAxisMinimum(0);
    ya.setDrawAxisLine(false);
    ya.setLabelCount(small ? 4 : 8, true);
    ya.setEnabled(true);
    ya.setDrawGridLines(true);
    ya.setGridColor(fgColor);
    ya.setValueFormatter(new CustomYAxisValueFormatter());

    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);

    data.addDataSet(initUploadSet(context));
    data.addDataSet(initDownloadSet(context));

    chart.invalidate();
}
 
Example 5
Source File: RadarChartActivity.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_radarchart);

    setTitle("RadarChartActivity");

    chart = findViewById(R.id.chart1);
    chart.setBackgroundColor(Color.rgb(60, 65, 82));

    chart.getDescription().setEnabled(false);

    chart.setWebLineWidth(1f);
    chart.setWebColor(Color.LTGRAY);
    chart.setWebLineWidthInner(1f);
    chart.setWebColorInner(Color.LTGRAY);
    chart.setWebAlpha(100);

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
    mv.setChartView(chart); // For bounds control
    chart.setMarker(mv); // Set the marker to the chart

    setData();

    chart.animateXY(1400, 1400, Easing.EaseInOutQuad);

    XAxis xAxis = chart.getXAxis();
    xAxis.setTypeface(tfLight);
    xAxis.setTextSize(9f);
    xAxis.setYOffset(0f);
    xAxis.setXOffset(0f);
    xAxis.setValueFormatter(new ValueFormatter() {

        private final String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};

        @Override
        public String getFormattedValue(float value) {
            return mActivities[(int) value % mActivities.length];
        }
    });
    xAxis.setTextColor(Color.WHITE);

    YAxis yAxis = chart.getYAxis();
    yAxis.setTypeface(tfLight);
    yAxis.setLabelCount(5, false);
    yAxis.setTextSize(9f);
    yAxis.setAxisMinimum(0f);
    yAxis.setAxisMaximum(80f);
    yAxis.setDrawLabels(false);

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setTypeface(tfLight);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(5f);
    l.setTextColor(Color.WHITE);
}
 
Example 6
Source File: RealtimeLineChartActivity.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_realtime_linechart);

    setTitle("RealtimeLineChartActivity");

    chart = findViewById(R.id.chart1);
    chart.setOnChartValueSelectedListener(this);

    // enable description text
    chart.getDescription().setEnabled(true);

    // enable touch gestures
    chart.setTouchEnabled(true);

    // enable scaling and dragging
    chart.setDragEnabled(true);
    chart.setScaleEnabled(true);
    chart.setDrawGridBackground(false);

    // if disabled, scaling can be done on x- and y-axis separately
    chart.setPinchZoom(true);

    // set an alternative background color
    chart.setBackgroundColor(Color.LTGRAY);

    LineData data = new LineData();
    data.setValueTextColor(Color.WHITE);

    // add empty data
    chart.setData(data);

    // get the legend (only possible after setting data)
    Legend l = chart.getLegend();

    // modify the legend ...
    l.setForm(LegendForm.LINE);
    l.setTypeface(tfLight);
    l.setTextColor(Color.WHITE);

    XAxis xl = chart.getXAxis();
    xl.setTypeface(tfLight);
    xl.setTextColor(Color.WHITE);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);
    xl.setEnabled(true);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tfLight);
    leftAxis.setTextColor(Color.WHITE);
    leftAxis.setAxisMaximum(100f);
    leftAxis.setAxisMinimum(0f);
    leftAxis.setDrawGridLines(true);

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);

}
 
Example 7
Source File: LineChartActivity2.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart);

        setTitle("LineChartActivity2");

        tvX = findViewById(R.id.tvXMax);
        tvY = findViewById(R.id.tvYMax);

        seekBarX = findViewById(R.id.seekBar1);
        seekBarX.setOnSeekBarChangeListener(this);

        seekBarY = findViewById(R.id.seekBar2);
        seekBarY.setOnSeekBarChangeListener(this);

        chart = findViewById(R.id.chart1);
        chart.setOnChartValueSelectedListener(this);

        // no description text
        chart.getDescription().setEnabled(false);

        // enable touch gestures
        chart.setTouchEnabled(true);

        chart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        chart.setDragEnabled(true);
        chart.setScaleEnabled(true);
        chart.setDrawGridBackground(false);
        chart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        chart.setPinchZoom(true);

        // set an alternative background color
        chart.setBackgroundColor(Color.LTGRAY);

        // add data
        seekBarX.setProgress(20);
        seekBarY.setProgress(30);

        chart.animateX(1500);

        // get the legend (only possible after setting data)
        Legend l = chart.getLegend();

        // modify the legend ...
        l.setForm(LegendForm.LINE);
        l.setTypeface(tfLight);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);
//        l.setYOffset(11f);

        XAxis xAxis = chart.getXAxis();
        xAxis.setTypeface(tfLight);
        xAxis.setTextSize(11f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);

        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.setTypeface(tfLight);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaximum(200f);
        leftAxis.setAxisMinimum(0f);
        leftAxis.setDrawGridLines(true);
        leftAxis.setGranularityEnabled(true);

        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setTypeface(tfLight);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaximum(900);
        rightAxis.setAxisMinimum(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
        rightAxis.setGranularityEnabled(false);
    }
 
Example 8
Source File: ChartUtil.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 显示图表
 *
 * @param context    上下文
 * @param lineChart  图表对象
 * @param yDataList  数据
 * @param title      图表标题(如:XXX趋势图)
 * @param curveLable 曲线图例名称(如:--用电量/时间)
 * @param unitName   坐标点击弹出提示框中数字单位(如:KWH)
 */
public static void showChart(Context context, LineChart lineChart,
                             List<Entry> yDataList, String title, String curveLable, String unitName) {
    // 设置数据
    lineChart.setData(setLineData(context, yDataList, curveLable));
    // 描述的显示和隐藏
    lineChart.getDescription().setEnabled(false);
    // 是否在折线图上添加边框
    lineChart.setDrawBorders(true);
    // 如果没有数据的时候,会显示这个,类似文本框的placeholder
    lineChart.setNoDataText(context.getString(R.string.no_data_chart));
    // 是否显示表格颜色
    lineChart.setDrawGridBackground(false);
    // 禁止绘制图表边框的线
    lineChart.setDrawBorders(false);
    // 表格的的颜色,在这里是是给颜色设置一个透明度
    // lineChart.setGridBackgroundColor(Color.WHITE & 0x70FFFFFF);
    // 设置是否启动触摸响应
    lineChart.setTouchEnabled(false);
    // 是否可以拖拽
    lineChart.setDragEnabled(false);
    // 是否可以缩放
    lineChart.setScaleEnabled(false);
    // 如果禁用,可以在x和y轴上分别进行缩放
    lineChart.setPinchZoom(false);
    // lineChart.setMarkerView(mv);
    // 设置背景色
    // lineChart.setBackgroundColor(getResources().getColor(R.color.bg_white));
    // 图例对象
    Legend mLegend = lineChart.getLegend();
    // mLegend.setPosition(LegendPosition.BELOW_CHART_CENTER);
    // 图例样式 (CIRCLE圆形;LINE线性;SQUARE是方块)
    mLegend.setForm(LegendForm.SQUARE);
    // 图例大小
    mLegend.setFormSize(8f);
    // 图例上的字体颜色
    mLegend.setTextColor(context.getApplicationContext().getResources().getColor(R.color.theme_color));
    mLegend.setTextSize(12f);
    // 图例字体
    // mLegend.setTypeface(mTf);
    // 图例的显示和隐藏
    mLegend.setEnabled(false);
    // 隐藏右侧Y轴(只在左侧的Y轴显示刻度)
    lineChart.getAxisRight().setEnabled(false);
    // 隐藏左侧Y轴(只在左侧的Y轴显示刻度)
    lineChart.getAxisLeft().setEnabled(false);
    XAxis xAxis = lineChart.getXAxis();
    // 显示X轴上的刻度值
    xAxis.setDrawLabels(false);
    // 设置X轴的数据显示在报表的下方
    xAxis.setPosition(XAxisPosition.BOTTOM);
    // 轴线
    xAxis.setDrawAxisLine(false);
    // 设置不从X轴发出纵向直线
    xAxis.setDrawGridLines(false);
    // 执行的动画,x轴(动画持续时间)
    lineChart.animateX(1500);
    lineChart.notifyDataSetChanged();
}
 
Example 9
Source File: RealtimeLineChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_realtime_linechart);

    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);

    // no description text
    mChart.setDescription("");
    mChart.setNoDataTextDescription("You need to provide data for the chart.");

    // enable touch gestures
    mChart.setTouchEnabled(true);

    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);
    mChart.setDrawGridBackground(false);

    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(true);

    // set an alternative background color
    mChart.setBackgroundColor(Color.LTGRAY);

    LineData data = new LineData();
    data.setValueTextColor(Color.WHITE);

    // add empty data
    mChart.setData(data);

    Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();

    // modify the legend ...
    // l.setPosition(LegendPosition.LEFT_OF_CHART);
    l.setForm(LegendForm.LINE);
    l.setTypeface(tf);
    l.setTextColor(Color.WHITE);

    XAxis xl = mChart.getXAxis();
    xl.setTypeface(tf);
    xl.setTextColor(Color.WHITE);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);
    xl.setSpaceBetweenLabels(5);
    xl.setEnabled(true);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    leftAxis.setTextColor(Color.WHITE);
    leftAxis.setAxisMaxValue(100f);
    leftAxis.setAxisMinValue(0f);
    leftAxis.setDrawGridLines(true);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);

}
 
Example 10
Source File: LineChartActivity2.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart);

        tvX = (TextView) findViewById(R.id.tvXMax);
        tvY = (TextView) findViewById(R.id.tvYMax);
        mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
        mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

        mSeekBarX.setProgress(45);
        mSeekBarY.setProgress(100);

        mSeekBarY.setOnSeekBarChangeListener(this);
        mSeekBarX.setOnSeekBarChangeListener(this);

        mChart = (LineChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        
        // no description text
        mChart.setDescription("");
        mChart.setNoDataTextDescription("You need to provide data for the chart.");

        // enable touch gestures
        mChart.setTouchEnabled(true);
        
        mChart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        mChart.setDragEnabled(true);
        mChart.setScaleEnabled(true);
        mChart.setDrawGridBackground(false);
        mChart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(true);

        // set an alternative background color
        mChart.setBackgroundColor(Color.LTGRAY);

        // add data
        setData(20, 30);

        mChart.animateX(2500);

        Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

        // get the legend (only possible after setting data)
        Legend l = mChart.getLegend();

        // modify the legend ...
        // l.setPosition(LegendPosition.LEFT_OF_CHART);
        l.setForm(LegendForm.LINE);
        l.setTypeface(tf);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setPosition(LegendPosition.BELOW_CHART_LEFT);
//        l.setYOffset(11f);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setTypeface(tf);
        xAxis.setTextSize(12f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);
        xAxis.setSpaceBetweenLabels(1);

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setTypeface(tf);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaxValue(200f);
        leftAxis.setAxisMinValue(0f);
        leftAxis.setDrawGridLines(true);
        
        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setTypeface(tf);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaxValue(900);
        rightAxis.setAxisMinValue(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
    }
 
Example 11
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
/**
 * More details about legend customization: https://github.com/PhilJay/MPAndroidChart/wiki/Legend
 */
@ReactProp(name = "legend")
public void setLegend(T chart, ReadableMap propMap) {
    Legend legend = chart.getLegend();

    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) {
        legend.setEnabled(propMap.getBoolean("enabled"));
    }

    // Styling
    if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) {
        legend.setTextColor(Color.parseColor(propMap.getString("textColor")));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
        legend.setTextSize((float) propMap.getDouble("textSize"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") ||
            BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) {
        legend.setTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily"));
    }

    // Wrapping / clipping avoidance
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "wordWrapEnabled")) {
        legend.setWordWrapEnabled(propMap.getBoolean("wordWrapEnabled"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "maxSizePercent")) {
        legend.setMaxSizePercent((float) propMap.getDouble("maxSizePercent"));
    }

    // Customizing
    if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
        legend.setPosition(LegendPosition.valueOf(propMap.getString("position").toUpperCase()));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "form")) {
        legend.setForm(LegendForm.valueOf(propMap.getString("form").toUpperCase()));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "formSize")) {
        legend.setFormSize((float) propMap.getDouble("formSize"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "xEntrySpace")) {
        legend.setXEntrySpace((float) propMap.getDouble("xEntrySpace"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "yEntrySpace")) {
        legend.setYEntrySpace((float) propMap.getDouble("yEntrySpace"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "formToTextSpace")) {
        legend.setFormToTextSpace((float) propMap.getDouble("formToTextSpace"));
    }

    // Custom labels & colors
    if (BridgeUtils.validate(propMap, ReadableType.Map, "custom")) {
        ReadableMap customMap = propMap.getMap("custom");
        if (BridgeUtils.validate(customMap, ReadableType.Array, "colors") &&
                BridgeUtils.validate(customMap, ReadableType.Array, "labels")) {

            ReadableArray colorsArray = customMap.getArray("colors");
            ReadableArray labelsArray = customMap.getArray("labels");

            if (colorsArray.size() == labelsArray.size()) {
                // TODO null label should start a group
                // TODO -2 color should avoid drawing a form
                String[] labels = BridgeUtils.convertToStringArray(labelsArray);
                String[] colors = BridgeUtils.convertToStringArray(colorsArray);

                int[] colorsParsed = new int[colors.length];
                for (int i = 0; i < colors.length; i++) {
                    colorsParsed[i] = Color.parseColor(colors[i]);
                }

                legend.setCustom(colorsParsed, labels);
            }
        }
    }

    // TODO resetCustom function
    // TODO extra

    chart.invalidate();     // TODO is this necessary? Looks like enabled is not refreshing without it
}
 
Example 12
Source File: StatisticsFragment.java    From openScale with GNU General Public License v3.0 4 votes vote down vote up
@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);
        }
    });

    return statisticsView;
}