Java Code Examples for com.github.mikephil.charting.components.Legend#LegendForm

The following examples show how to use com.github.mikephil.charting.components.Legend#LegendForm . 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: BaseDataSet.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
public void setForm(Legend.LegendForm form) {
    mForm = form;
}
 
Example 2
Source File: BaseDataSet.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public Legend.LegendForm getForm() {
    return mForm;
}
 
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: BaseDataSet.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
public void setForm(Legend.LegendForm form) {
    mForm = form;
}
 
Example 5
Source File: BaseDataSet.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public Legend.LegendForm getForm() {
    return mForm;
}
 
Example 6
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 7
Source File: BaseDataSet.java    From android-kline with Apache License 2.0 4 votes vote down vote up
public void setForm(Legend.LegendForm form) {
    mForm = form;
}
 
Example 8
Source File: BaseDataSet.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public Legend.LegendForm getForm() {
    return mForm;
}
 
Example 9
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 10
Source File: IDataSet.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
/**
 * The form to draw for this dataset in the legend.
 * <p/>
 * Return `DEFAULT` to use the default legend form.
 */
Legend.LegendForm getForm();
 
Example 11
Source File: IDataSet.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * The form to draw for this dataset in the legend.
 * <p/>
 * Return `DEFAULT` to use the default legend form.
 */
Legend.LegendForm getForm();
 
Example 12
Source File: IDataSet.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * The form to draw for this dataset in the legend.
 * <p/>
 * Return `DEFAULT` to use the default legend form.
 */
Legend.LegendForm getForm();