Java Code Examples for com.github.mikephil.charting.data.BarData#getGroupSpace()

The following examples show how to use com.github.mikephil.charting.data.BarData#getGroupSpace() . 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: BarChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    BarData barData = mChart.getBarData();
    mBarBuffers = new BarBuffer[barData.getDataSetCount()];

    for (int i = 0; i < mBarBuffers.length; i++) {
        IBarDataSet set = barData.getDataSetByIndex(i);
        mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
                barData.getGroupSpace(),
                barData.getDataSetCount(), set.isStacked());
    }
}
 
Example 2
Source File: HorizontalBarChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    BarData barData = mChart.getBarData();
    mBarBuffers = new HorizontalBarBuffer[barData.getDataSetCount()];

    for (int i = 0; i < mBarBuffers.length; i++) {
        IBarDataSet set = barData.getDataSetByIndex(i);
        mBarBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
                barData.getGroupSpace(),
                barData.getDataSetCount(), set.isStacked());
    }
}
 
Example 3
Source File: BarChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    BarData barData = mChart.getBarData();
    mBarBuffers = new BarBuffer[barData.getDataSetCount()];

    for (int i = 0; i < mBarBuffers.length; i++) {
        IBarDataSet set = barData.getDataSetByIndex(i);
        mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
                barData.getGroupSpace(),
                barData.getDataSetCount(), set.isStacked());
    }
}
 
Example 4
Source File: XAxisRendererBarChart.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderGridLines(Canvas c) {

    if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
        return;

    float[] position = new float[] {
            0f, 0f
    };

    mGridPaint.setColor(mXAxis.getGridColor());
    mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());

    BarData bd = mChart.getData();
    int step = bd.getDataSetCount();

    for (int i = mMinX; i < mMaxX; i += mXAxis.mAxisLabelModulus) {

        position[0] = i * step + i * bd.getGroupSpace() - 0.5f;

        mTrans.pointValuesToPixel(position);

        if (mViewPortHandler.isInBoundsX(position[0])) {

            c.drawLine(position[0], mViewPortHandler.offsetTop(), position[0],
                    mViewPortHandler.contentBottom(), mGridPaint);
        }
    }
}
 
Example 5
Source File: XAxisRendererHorizontalBarChart.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderGridLines(Canvas c) {

    if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
        return;

    float[] position = new float[] {
            0f, 0f
    };
    
    mGridPaint.setColor(mXAxis.getGridColor());
    mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());

    BarData bd = mChart.getData();
    // take into consideration that multiple DataSets increase mDeltaX
    int step = bd.getDataSetCount();

    for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {

        position[1] = i * step + i * bd.getGroupSpace() - 0.5f;

        mTrans.pointValuesToPixel(position);

        if (mViewPortHandler.isInBoundsY(position[1])) {

            c.drawLine(mViewPortHandler.contentLeft(), position[1],
                    mViewPortHandler.contentRight(), position[1], mGridPaint);
        }
    }
}
 
Example 6
Source File: XAxisRendererHorizontalBarChart.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * draws the x-labels on the specified y-position
 * 
 * @param pos
 */
@Override
protected void drawLabels(Canvas c, float pos, PointF anchor) {

    final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();

    // pre allocate to save performance (dont allocate in loop)
    float[] position = new float[] {
            0f, 0f
    };

    BarData bd = mChart.getData();
    int step = bd.getDataSetCount();

    for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {

        position[1] = i * step + i * bd.getGroupSpace()
                + bd.getGroupSpace() / 2f;
        
        // consider groups (center label for each group)
        if (step > 1) {
            position[1] += ((float) step - 1f) / 2f;
        }

        mTrans.pointValuesToPixel(position);

        if (mViewPortHandler.isInBoundsY(position[1])) {

            String label = mXAxis.getValues().get(i);
            drawLabel(c, label, i, pos, position[1], anchor, labelRotationAngleDegrees);
        }
    }
}
 
Example 7
Source File: Transformer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 *
 * @param data
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesHorizontalBarChart(IBarDataSet data,
                                                           int dataSet, BarData bd, float phaseY) {

    float[] valuePoints = new float[data.getEntryCount() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = data.getEntryForIndex(j / 2);
        int i = e.getXIndex();

        // calculate the x-position, depending on datasetcount
        float x = i + i * (setCount - 1) + dataSet + space * i
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = y * phaseY;
        valuePoints[j + 1] = x;
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 8
Source File: Transformer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 *
 * @param data
 * @param dataSetIndex the dataset index
 * @param bd
 * @param phaseY
 * @return
 */
public float[] generateTransformedValuesBarChart(IBarDataSet data,
                                                 int dataSetIndex, BarData bd, float phaseY) {

    float[] valuePoints = new float[data.getEntryCount() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = data.getEntryForIndex(j / 2);
        int i = e.getXIndex();

        // calculate the x-position, depending on datasetcount
        float x = e.getXIndex() + i * (setCount - 1) + dataSetIndex + space * i
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = x;
        valuePoints[j + 1] = y * phaseY;
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 9
Source File: HorizontalBarChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    BarData barData = mChart.getBarData();
    mBarBuffers = new HorizontalBarBuffer[barData.getDataSetCount()];

    for (int i = 0; i < mBarBuffers.length; i++) {
        IBarDataSet set = barData.getDataSetByIndex(i);
        mBarBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
                barData.getGroupSpace(),
                barData.getDataSetCount(), set.isStacked());
    }
}
 
Example 10
Source File: Chart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * Transforms an arraylist of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 * 
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
protected float[] generateTransformedValuesBarChart(ArrayList<? extends Entry> entries,
        int dataSet) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = mOriginalData.getDataSetCount();
    BarData bd = (BarData) mOriginalData;
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = entries.get(j / 2);

        // calculate the x-position, depending on datasetcount
        float x = e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet + 0.5f + space * (j / 2)
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = x;
        valuePoints[j + 1] = y * mPhaseY;
    }

    transformPointArray(valuePoints);

    return valuePoints;
}
 
Example 11
Source File: XAxisRendererBarChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void renderGridLines(Canvas c) {

    if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
        return;

    float[] position = new float[] {
            0f, 0f
    };

    mGridPaint.setColor(mXAxis.getGridColor());
    mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());

    BarData bd = mChart.getData();
    int step = bd.getDataSetCount();

    for (int i = mMinX; i < mMaxX; i += mXAxis.mAxisLabelModulus) {

        position[0] = i * step + i * bd.getGroupSpace() - 0.5f;

        mTrans.pointValuesToPixel(position);

        if (mViewPortHandler.isInBoundsX(position[0])) {

            c.drawLine(position[0], mViewPortHandler.offsetTop(), position[0],
                    mViewPortHandler.contentBottom(), mGridPaint);
        }
    }
}
 
Example 12
Source File: XAxisRendererHorizontalBarChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * draws the x-labels on the specified y-position
 * 
 * @param pos
 */
@Override
protected void drawLabels(Canvas c, float pos, PointF anchor) {

    final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();

    // pre allocate to save performance (dont allocate in loop)
    float[] position = new float[] {
            0f, 0f
    };

    BarData bd = mChart.getData();
    int step = bd.getDataSetCount();

    for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {

        position[1] = i * step + i * bd.getGroupSpace()
                + bd.getGroupSpace() / 2f;
        
        // consider groups (center label for each group)
        if (step > 1) {
            position[1] += ((float) step - 1f) / 2f;
        }

        mTrans.pointValuesToPixel(position);

        if (mViewPortHandler.isInBoundsY(position[1])) {

            String label = mXAxis.getValues().get(i);
            drawLabel(c, label, i, pos, position[1], anchor, labelRotationAngleDegrees);
        }
    }
}
 
Example 13
Source File: Transformer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 * 
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesHorizontalBarChart(List<? extends Entry> entries,
        int dataSet, BarData bd, float phaseY) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = entries.get(j / 2);
        int i = e.getXIndex();

        // calculate the x-position, depending on datasetcount
        float x = i + i * (setCount - 1) + dataSet + space * i
                + space / 2f ;
        float y = e.getVal();

        valuePoints[j] = y * phaseY;
        valuePoints[j + 1] = x;
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 14
Source File: Transformer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 * 
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesBarChart(List<? extends Entry> entries,
        int dataSet, BarData bd, float phaseY) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = entries.get(j / 2);
        int i = e.getXIndex();

        // calculate the x-position, depending on datasetcount
        float x = e.getXIndex() + i * (setCount - 1) + dataSet + space * i
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = x;
        valuePoints[j + 1] = y * phaseY;
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 15
Source File: HorizontalBarChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    BarData barData = mChart.getBarData();
    mBarBuffers = new HorizontalBarBuffer[barData.getDataSetCount()];

    for (int i = 0; i < mBarBuffers.length; i++) {
        BarDataSet set = barData.getDataSetByIndex(i);
        mBarBuffers[i] = new HorizontalBarBuffer(set.getValueCount() * 4 * set.getStackSize(),
                barData.getGroupSpace(),
                barData.getDataSetCount(), set.isStacked());
    }
}
 
Example 16
Source File: BarChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    BarData barData = mChart.getBarData();
    mBarBuffers = new BarBuffer[barData.getDataSetCount()];

    for (int i = 0; i < mBarBuffers.length; i++) {
        BarDataSet set = barData.getDataSetByIndex(i);
        mBarBuffers[i] = new BarBuffer(set.getValueCount() * 4 * set.getStackSize(),
                barData.getGroupSpace(),
                barData.getDataSetCount(), set.isStacked());
    }
}
 
Example 17
Source File: XAxisRendererBarChart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void renderGridLines(Canvas c) {

    if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
        return;

    float[] position = new float[] {
            0f, 0f
    };

    mGridPaint.setColor(mXAxis.getGridColor());
    mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());

    BarData bd = mChart.getData();
    int step = bd.getDataSetCount();

    for (int i = mMinX; i < mMaxX; i += mXAxis.mAxisLabelModulus) {

        position[0] = i * step + i * bd.getGroupSpace() - 0.5f;

        mTrans.pointValuesToPixel(position);

        if (mViewPortHandler.isInBoundsX(position[0])) {

            c.drawLine(position[0], mViewPortHandler.offsetTop(), position[0],
                    mViewPortHandler.contentBottom(), mGridPaint);
        }
    }
}
 
Example 18
Source File: XAxisRendererHorizontalBarChart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void renderGridLines(Canvas c) {

    if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
        return;

    float[] position = new float[] {
            0f, 0f
    };
    
    mGridPaint.setColor(mXAxis.getGridColor());
    mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());

    BarData bd = mChart.getData();
    // take into consideration that multiple DataSets increase mDeltaX
    int step = bd.getDataSetCount();

    for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {

        position[1] = i * step + i * bd.getGroupSpace() - 0.5f;

        mTrans.pointValuesToPixel(position);

        if (mViewPortHandler.isInBoundsY(position[1])) {

            c.drawLine(mViewPortHandler.contentLeft(), position[1],
                    mViewPortHandler.contentRight(), position[1], mGridPaint);
        }
    }
}
 
Example 19
Source File: Chart.java    From Notification-Analyser with MIT License 4 votes vote down vote up
/**
 * Returns the actual position in pixels of the MarkerView for the given
 * Entry in the given DataSet.
 * 
 * @param xIndex
 * @param dataSetIndex
 * @return
 */
private float[] getMarkerPosition(Entry e, int dataSetIndex) {

    float xPos = (float) e.getXIndex();

    // make sure the marker is in the center of the bars in BarChart and
    // CandleStickChart
    if (this instanceof CandleStickChart)
        xPos += 0.5f;

    else if (this instanceof BarChart) {

        BarData bd = (BarData) mCurrentData;
        float space = bd.getGroupSpace();
        float j = mCurrentData.getDataSetByIndex(dataSetIndex)
                .getEntryPosition(e);

        float x = (j * (mCurrentData.getDataSetCount() - 1)) + dataSetIndex + space * j + space
                / 2f + 0.5f;

        xPos += x;
    } else if (this instanceof RadarChart) {

        RadarChart rc = (RadarChart) this;
        float angle = rc.getSliceAngle() * e.getXIndex() + rc.getRotationAngle();
        float val = e.getVal() * rc.getFactor();
        PointF c = getCenterOffsets();

        PointF p = new PointF((float) (c.x + val * Math.cos(Math.toRadians(angle))),
                (float) (c.y + val * Math.sin(Math.toRadians(angle))));

        return new float[] {
                p.x, p.y
        };
    }

    // position of the marker depends on selected value index and value
    float[] pts = new float[] {
            xPos, e.getVal() * mPhaseY
    };

    transformPointArray(pts);

    return pts;
}
 
Example 20
Source File: BarChartRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BarData barData = mChart.getBarData();
    int setCount = barData.getDataSetCount();

    for (Highlight high : indices) {

        final int minDataSetIndex = high.getDataSetIndex() == -1
                ? 0
                : high.getDataSetIndex();
        final int maxDataSetIndex = high.getDataSetIndex() == -1
                ? barData.getDataSetCount()
                : (high.getDataSetIndex() + 1);
        if (maxDataSetIndex - minDataSetIndex < 1) continue;

        for (int dataSetIndex = minDataSetIndex;
                dataSetIndex < maxDataSetIndex;
                dataSetIndex++) {

            IBarDataSet set = barData.getDataSetByIndex(dataSetIndex);

            if (set == null || !set.isHighlightEnabled())
                continue;

            float barspaceHalf = set.getBarSpace() / 2f;

            Transformer trans = mChart.getTransformer(set.getAxisDependency());

            mHighlightPaint.setColor(set.getHighLightColor());
            mHighlightPaint.setAlpha(set.getHighLightAlpha());

            int index = high.getXIndex();

            // check outofbounds
            if (index >= 0
                    && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) {

                BarEntry e = set.getEntryForXIndex(index);

                if (e == null || e.getXIndex() != index)
                    continue;

                float groupspace = barData.getGroupSpace();
                boolean isStack = high.getStackIndex() < 0 ? false : true;

                // calculate the correct x-position
                float x = index * setCount + dataSetIndex + groupspace / 2f
                        + groupspace * index;

                final float y1;
                final float y2;

                if (isStack) {
                    y1 = high.getRange().from;
                    y2 = high.getRange().to;
                } else {
                    y1 = e.getVal();
                    y2 = 0.f;
                }

                prepareBarHighlight(x, y1, y2, barspaceHalf, trans);

                c.drawRect(mBarRect, mHighlightPaint);

                if (mChart.isDrawHighlightArrowEnabled()) {

                    mHighlightPaint.setAlpha(255);

                    // distance between highlight arrow and bar
                    float offsetY = mAnimator.getPhaseY() * 0.07f;

                    float[] values = new float[9];
                    trans.getPixelToValueMatrix().getValues(values);
                    final float xToYRel = Math.abs(
                            values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]);

                    final float arrowWidth = set.getBarSpace() / 2.f;
                    final float arrowHeight = arrowWidth * xToYRel;

                    final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY();

                    Path arrow = new Path();
                    arrow.moveTo(x + 0.4f, yArrow + offsetY);
                    arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight);
                    arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight);

                    trans.pathValueToPixel(arrow);
                    c.drawPath(arrow, mHighlightPaint);
                }
            }
        }
    }
}