Java Code Examples for com.github.mikephil.charting.components.YAxis.AxisDependency#LEFT

The following examples show how to use com.github.mikephil.charting.components.YAxis.AxisDependency#LEFT . 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: ChartData.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Adjusts the current minimum and maximum values based on the provided Entry object.
 *
 * @param e
 * @param axis
 */
protected void calcMinMax(Entry e, AxisDependency axis) {

    if (mYMax < e.getY())
        mYMax = e.getY();
    if (mYMin > e.getY())
        mYMin = e.getY();

    if (mXMax < e.getX())
        mXMax = e.getX();
    if (mXMin > e.getX())
        mXMin = e.getX();

    if (axis == AxisDependency.LEFT) {

        if (mLeftAxisMax < e.getY())
            mLeftAxisMax = e.getY();
        if (mLeftAxisMin > e.getY())
            mLeftAxisMin = e.getY();
    } else {
        if (mRightAxisMax < e.getY())
            mRightAxisMax = e.getY();
        if (mRightAxisMin > e.getY())
            mRightAxisMin = e.getY();
    }
}
 
Example 2
Source File: ChartData.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Adjusts the minimum and maximum values based on the given DataSet.
 *
 * @param d
 */
protected void calcMinMax(T d) {

    if (mYMax < d.getYMax())
        mYMax = d.getYMax();
    if (mYMin > d.getYMin())
        mYMin = d.getYMin();

    if (mXMax < d.getXMax())
        mXMax = d.getXMax();
    if (mXMin > d.getXMin())
        mXMin = d.getXMin();

    if (d.getAxisDependency() == AxisDependency.LEFT) {

        if (mLeftAxisMax < d.getYMax())
            mLeftAxisMax = d.getYMax();
        if (mLeftAxisMin > d.getYMin())
            mLeftAxisMin = d.getYMin();
    } else {
        if (mRightAxisMax < d.getYMax())
            mRightAxisMax = d.getYMax();
        if (mRightAxisMin > d.getYMin())
            mRightAxisMin = d.getYMin();
    }
}
 
Example 3
Source File: YAxisRendererHorizontalBarChart.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
public void renderAxisLine(Canvas c) {

    if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled())
        return;

    mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
    mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());

    if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
        c.drawLine(mViewPortHandler.contentLeft(),
                mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
                mViewPortHandler.contentTop(), mAxisLinePaint);
    } else {
        c.drawLine(mViewPortHandler.contentLeft(),
                mViewPortHandler.contentBottom(), mViewPortHandler.contentRight(),
                mViewPortHandler.contentBottom(), mAxisLinePaint);
    }
}
 
Example 4
Source File: ChartData.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Returns the maximum y-value for the specified axis.
 *
 * @param axis
 * @return
 */
public float getYMax(AxisDependency axis) {
    if (axis == AxisDependency.LEFT) {

        if (mLeftAxisMax == -Float.MAX_VALUE) {
            return mRightAxisMax;
        } else {
            return mLeftAxisMax;
        }
    } else {
        if (mRightAxisMax == -Float.MAX_VALUE) {
            return mLeftAxisMax;
        } else {
            return mRightAxisMax;
        }
    }
}
 
Example 5
Source File: YAxisRendererHorizontalBarChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void renderAxisLine(Canvas c) {

    if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled()) {
        return;
    }

    mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
    mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());

    if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
        c.drawLine(mViewPortHandler.contentLeft(),
                mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
                mViewPortHandler.contentTop(), mAxisLinePaint);
    } else {
        c.drawLine(mViewPortHandler.contentLeft(),
                mViewPortHandler.contentBottom(), mViewPortHandler.contentRight(),
                mViewPortHandler.contentBottom(), mAxisLinePaint);
    }
}
 
Example 6
Source File: ChartData.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Adjusts the current minimum and maximum values based on the provided Entry object.
 *
 * @param e
 * @param axis
 */
protected void calcMinMax(Entry e, AxisDependency axis) {

    if (mYMax < e.getY())
        mYMax = e.getY();
    if (mYMin > e.getY())
        mYMin = e.getY();

    if (mXMax < e.getX())
        mXMax = e.getX();
    if (mXMin > e.getX())
        mXMin = e.getX();

    if (axis == AxisDependency.LEFT) {

        if (mLeftAxisMax < e.getY())
            mLeftAxisMax = e.getY();
        if (mLeftAxisMin > e.getY())
            mLeftAxisMin = e.getY();
    } else {
        if (mRightAxisMax < e.getY())
            mRightAxisMax = e.getY();
        if (mRightAxisMin > e.getY())
            mRightAxisMin = e.getY();
    }
}
 
Example 7
Source File: ChartData.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the minimum y-value for the specified axis.
 *
 * @param axis
 * @return
 */
public float getYMin(AxisDependency axis) {
    if (axis == AxisDependency.LEFT)
        return mLeftAxisMin;
    else
        return mRightAxisMin;
}
 
Example 8
Source File: BarLineChartBase.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    mAxisLeft = new YAxis(AxisDependency.LEFT);
    mAxisRight = new YAxis(AxisDependency.RIGHT);

    mXAxis = new XAxis();

    mLeftAxisTransformer = new Transformer(mViewPortHandler);
    mRightAxisTransformer = new Transformer(mViewPortHandler);

    mAxisRendererLeft = new YAxisRenderer(mViewPortHandler, mAxisLeft, mLeftAxisTransformer);
    mAxisRendererRight = new YAxisRenderer(mViewPortHandler, mAxisRight, mRightAxisTransformer);

    mXAxisRenderer = new XAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);

    mHighlighter = new ChartHighlighter(this);

    mChartTouchListener = new BarLineChartTouchListener(this, mViewPortHandler.getMatrixTouch());

    mGridBackgroundPaint = new Paint();
    mGridBackgroundPaint.setStyle(Style.FILL);
    // mGridBackgroundPaint.setColor(Color.WHITE);
    mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240)); // light
    // grey

    mBorderPaint = new Paint();
    mBorderPaint.setStyle(Style.STROKE);
    mBorderPaint.setColor(Color.BLACK);
    mBorderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}
 
Example 9
Source File: ChartData.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the maximum y-value for the specified axis.
 *
 * @param axis
 * @return
 */
public float getYMax(AxisDependency axis) {
    if (axis == AxisDependency.LEFT) {

        if (mLeftAxisMax == -Float.MAX_VALUE) {
            return mRightAxisMax;
        } else
            return mLeftAxisMax;
    } else {
        if (mRightAxisMax == -Float.MAX_VALUE) {
            return mLeftAxisMax;
        } else
            return mRightAxisMax;
    }
}
 
Example 10
Source File: ChartData.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the first DataSet from the datasets-array that has it's dependency on the left axis.
 * Returns null if no DataSet with left dependency could be found.
 *
 * @return
 */
public T getFirstLeft() {
    for (T dataSet : mDataSets) {
        if (dataSet.getAxisDependency() == AxisDependency.LEFT)
            return dataSet;
    }

    return null;
}
 
Example 11
Source File: BarLineChartBase.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the delta-y value (y-value range) of the specified axis.
 * 
 * @param axis
 * @return
 */
public float getDeltaY(AxisDependency axis) {
    if (axis == AxisDependency.LEFT)
        return mAxisLeft.mAxisRange;
    else
        return mAxisRight.mAxisRange;
}
 
Example 12
Source File: BarLineChartBase.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    mAxisLeft = new YAxis(AxisDependency.LEFT);
    mAxisRight = new YAxis(AxisDependency.RIGHT);

    mLeftAxisTransformer = new Transformer(mViewPortHandler);
    mRightAxisTransformer = new Transformer(mViewPortHandler);

    mAxisRendererLeft = new YAxisRenderer(mViewPortHandler, mAxisLeft, mLeftAxisTransformer);
    mAxisRendererRight = new YAxisRenderer(mViewPortHandler, mAxisRight, mRightAxisTransformer);

    mXAxisRenderer = new XAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);

    setHighlighter(new ChartHighlighter(this));

    mChartTouchListener = new BarLineChartTouchListener(this, mViewPortHandler.getMatrixTouch());

    mGridBackgroundPaint = new Paint();
    mGridBackgroundPaint.setStyle(Style.FILL);
    // mGridBackgroundPaint.setColor(Color.WHITE);
    mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240)); // light
    // grey

    mBorderPaint = new Paint();
    mBorderPaint.setStyle(Style.STROKE);
    mBorderPaint.setColor(Color.BLACK);
    mBorderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}
 
Example 13
Source File: YAxisRendererHorizontalBarChart.java    From android-kline with Apache License 2.0 4 votes vote down vote up
/**
 * draws the y-axis labels to the screen
 */
@Override
public void renderAxisLabels(Canvas c) {

    if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
        return;

    float[] positions = getTransformedPositions();

    mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
    mAxisLabelPaint.setColor(mYAxis.getTextColor());
    mAxisLabelPaint.setTextAlign(Align.CENTER);

    float baseYOffset = Utils.convertDpToPixel(2.5f);
    float textHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");

    AxisDependency dependency = mYAxis.getAxisDependency();
    YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();

    float yPos = 0f;

    if (dependency == AxisDependency.LEFT) {

        if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
            yPos = mViewPortHandler.contentTop() - baseYOffset;
        } else {
            yPos = mViewPortHandler.contentTop() - baseYOffset;
        }

    } else {

        if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
            yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
        } else {
            yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
        }
    }

    drawYLabels(c, yPos, positions, mYAxis.getYOffset());
}
 
Example 14
Source File: YAxisRendererHorizontalBarChart.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
/**
 * draws the y-axis labels to the screen
 */
@Override
public void renderAxisLabels(Canvas c) {

    if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
        return;

    float[] positions = new float[mYAxis.mEntryCount * 2];

    for (int i = 0; i < positions.length; i += 2) {
        // only fill y values, x values are not needed since the y-labels
        // are
        // static on the x-axis
        positions[i] = mYAxis.mEntries[i / 2];
    }

    mTrans.pointValuesToPixel(positions);

    mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
    mAxisLabelPaint.setColor(mYAxis.getTextColor());
    mAxisLabelPaint.setTextAlign(Align.CENTER);

    float baseYOffset = Utils.convertDpToPixel(2.5f);
    float textHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");

    AxisDependency dependency = mYAxis.getAxisDependency();
    YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();

    float yPos = 0f;

    if (dependency == AxisDependency.LEFT) {

        if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
            yPos = mViewPortHandler.contentTop() - baseYOffset;
        } else {
            yPos = mViewPortHandler.contentTop() - baseYOffset;
        }

    } else {

        if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
            yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
        } else {
            yPos = mViewPortHandler.contentBottom() + textHeight + baseYOffset;
        }
    }

    drawYLabels(c, yPos, positions, mYAxis.getYOffset());
}
 
Example 15
Source File: YAxisRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
/**
 * draws the y-axis labels to the screen
 */
@Override
public void renderAxisLabels(Canvas c) {

    if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
        return;

    float[] positions = new float[mYAxis.mEntryCount * 2];

    for (int i = 0; i < positions.length; i += 2) {
        // only fill y values, x values are not needed since the y-labels
        // are
        // static on the x-axis
        positions[i + 1] = mYAxis.mEntries[i / 2];
    }

    mTrans.pointValuesToPixel(positions);

    mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
    mAxisLabelPaint.setColor(mYAxis.getTextColor());

    float xoffset = mYAxis.getXOffset();
    float yoffset = Utils.calcTextHeight(mAxisLabelPaint, "A") / 2.5f + mYAxis.getYOffset();

    AxisDependency dependency = mYAxis.getAxisDependency();
    YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();

    float xPos = 0f;

    if (dependency == AxisDependency.LEFT) {

        if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
            mAxisLabelPaint.setTextAlign(Align.RIGHT);
            xPos = mViewPortHandler.offsetLeft() - xoffset;
        } else {
            mAxisLabelPaint.setTextAlign(Align.LEFT);
            xPos = mViewPortHandler.offsetLeft() + xoffset;
        }

    } else {

        if (labelPosition == YAxisLabelPosition.OUTSIDE_CHART) {
            mAxisLabelPaint.setTextAlign(Align.LEFT);
            xPos = mViewPortHandler.contentRight() + xoffset;
        } else {
            mAxisLabelPaint.setTextAlign(Align.RIGHT);
            xPos = mViewPortHandler.contentRight() - xoffset;
        }
    }

    drawYLabels(c, xPos, positions, yoffset);
}
 
Example 16
Source File: BarLineChartBase.java    From iMoney with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the y-axis object to the corresponding AxisDependency. In the
 * horizontal bar-chart, LEFT == top, RIGHT == BOTTOM
 * 
 * @param axis
 * @return
 */
public YAxis getAxis(AxisDependency axis) {
    if (axis == AxisDependency.LEFT)
        return mAxisLeft;
    else
        return mAxisRight;
}
 
Example 17
Source File: BarLineChartBase.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the y-axis object to the corresponding AxisDependency. In the
 * horizontal bar-chart, LEFT == top, RIGHT == BOTTOM
 *
 * @param axis
 * @return
 */
public YAxis getAxis(AxisDependency axis) {
    if (axis == AxisDependency.LEFT)
        return mAxisLeft;
    else
        return mAxisRight;
}
 
Example 18
Source File: BarLineChartBase.java    From NetKnight with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the Transformer class that contains all matrices and is
 * responsible for transforming values into pixels on the screen and
 * backwards.
 *
 * @return
 */
public Transformer getTransformer(AxisDependency which) {
    if (which == AxisDependency.LEFT)
        return mLeftAxisTransformer;
    else
        return mRightAxisTransformer;
}
 
Example 19
Source File: BarLineChartBase.java    From android-kline with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the Transformer class that contains all matrices and is
 * responsible for transforming values into pixels on the screen and
 * backwards.
 *
 * @return
 */
public Transformer getTransformer(AxisDependency which) {
    if (which == AxisDependency.LEFT)
        return mLeftAxisTransformer;
    else
        return mRightAxisTransformer;
}
 
Example 20
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 3 votes vote down vote up
/**
 * Returns the y-axis object to the corresponding AxisDependency. In the
 * horizontal bar-chart, LEFT == top, RIGHT == BOTTOM
 *
 * @param axis
 * @return
 */
public YAxis getAxis(AxisDependency axis) {
    if (axis == AxisDependency.LEFT)
        return mAxisLeft;
    else
        return mAxisRight;
}