com.github.mikephil.charting.components.LegendEntry Java Examples

The following examples show how to use com.github.mikephil.charting.components.LegendEntry. 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: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 2019/7/31
 * author: chenli
 * description: 刷新均线图标值
 */
private void refreshTopChartLegend(int index) {
    List<LegendEntry> legendEntries = new ArrayList<>();
    for (int i = 0; i < mas.size(); i++) {
        int para = mas.get(i);
        Entry entry = mLineData.getDataSetByIndex(i).getEntryForXValue(index, 0.0f);
        String data = ":";
        if (entry != null) data = data + MathUtils.round(entry.getY()+"", 2);
        LegendEntry ma = new LegendEntry("MA" + para + data, Legend.LegendForm.NONE,
                NaN, NaN, null, mColorMas[i]);
        legendEntries.add(ma);
    }
    Legend legend = mTopChartViewBase.getLegend();
    legend.setCustom(legendEntries);
    legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
}
 
Example #2
Source File: BaseChartFragment.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * date: 2019/7/31
 * author: chenli
 * description: 刷新中部图标值
 */
protected void refreshChartLegend(int index){
    Map<String, KlineEntity.DataEntity> dataEntities = mKlineEntity.getData();
    int middleIndex = index;
    if (!CURRENT_DAY_FRAGMENT.equals(mFragmentType)) middleIndex = middleIndex + mBaseIndex;
    KlineEntity.DataEntity dataEntity = dataEntities.get(String.valueOf(middleIndex));
    if (dataEntity != null){
        List<LegendEntry> legendEntriesMiddle = new ArrayList<>();
        legendEntriesMiddle.add(new LegendEntry("OI:"+dataEntity.getClose_oi(), Legend.LegendForm.NONE,
                NaN, NaN, null, mOIColor));
        legendEntriesMiddle.add(new LegendEntry("VOL:"+dataEntity.getVolume(), Legend.LegendForm.NONE,
                NaN, NaN, null, mIncreasingColor));
        Legend legendMiddle = mMiddleChartViewBase.getLegend();
        legendMiddle.setCustom(legendEntriesMiddle);
        legendMiddle.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        legendMiddle.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    }

    Float emasF = mEMAs.get(index);
    Float emalF = mEMAl.get(index);
    if (emasF != null && emalF != null){
        float emas = mEMAs.get(index);
        float emal = mEMAl.get(index);
        String dif = MathUtils.round((emas - emal) + "", 2);
        String dea = MathUtils.round(mDEA.get(index) + "", 2);
        List<LegendEntry> legendEntriesBottom = new ArrayList<>();
        legendEntriesBottom.add(new LegendEntry("MACD(12,26,9)" , Legend.LegendForm.NONE,
                NaN, NaN, null, mDeaColor));
        legendEntriesBottom.add(new LegendEntry("DIFF:"+dif, Legend.LegendForm.NONE,
                NaN, NaN, null, mDiffColor));
        legendEntriesBottom.add(new LegendEntry("DEA:"+dea, Legend.LegendForm.NONE,
                NaN, NaN, null, mDeaColor));
        Legend legendBottom = mBottomChartViewBase.getLegend();
        legendBottom.setCustom(legendEntriesBottom);
        legendBottom.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        legendBottom.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    }

}
 
Example #3
Source File: LegendRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0) {
        return;
    }

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT) {
        form = legend.getForm();
    }

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE: {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
        break;
    }

    c.restoreToCount(restoreCount);
}
 
Example #4
Source File: LegendRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0)
        return;

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT)
        form = legend.getForm();

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE:
        {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
            break;
    }

    c.restoreToCount(restoreCount);
}
 
Example #5
Source File: LegendRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0)
        return;

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT)
        form = legend.getForm();

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE:
        {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
            break;
    }

    c.restoreToCount(restoreCount);
}
 
Example #6
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;
}