Java Code Examples for com.github.mikephil.charting.interfaces.datasets.IBarDataSet#getEntryCount()

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.IBarDataSet#getEntryCount() . 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: Transformer.java    From NetKnight 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 3
Source File: Transformer.java    From NetKnight 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 4
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 5
Source File: BarChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    BarData barData = mChart.getBarData();

    for (int i = 0; i < barData.getDataSetCount(); i++) {

        IBarDataSet set = barData.getDataSetByIndex(i);

        if (set.isVisible() && set.getEntryCount() > 0) {
            drawDataSet(c, set, i);
        }
    }
}
 
Example 6
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 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: BarChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    BarData barData = mChart.getBarData();

    for (int i = 0; i < barData.getDataSetCount(); i++) {

        IBarDataSet set = barData.getDataSetByIndex(i);

        if (set.isVisible() && set.getEntryCount() > 0) {
            drawDataSet(c, set, i);
        }
    }
}
 
Example 11
Source File: BarChartRenderer.java    From android-kline 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.getDataSetCount(), set.isStacked());
    }
}
 
Example 12
Source File: HorizontalBarChartRenderer.java    From android-kline 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.getDataSetCount(), set.isStacked());
    }
}
 
Example 13
Source File: BarChartRenderer.java    From android-kline 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.getDataSetCount(), set.isStacked());
    }
}
 
Example 14
Source File: HorizontalBarChartRenderer.java    From Ticket-Analysis with MIT License 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.getDataSetCount(), set.isStacked());
    }
}
 
Example 15
Source File: BarChartRenderer.java    From Ticket-Analysis with MIT License 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.getDataSetCount(), set.isStacked());
    }
}
 
Example 16
Source File: HorizontalBarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 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.getDataSetCount(), set.isStacked());
    }
}
 
Example 17
Source File: HistogramChart.java    From walt with Apache License 2.0 5 votes vote down vote up
/**
 * Re-implementation of BarData.groupBars(), but allows grouping with only 1 BarDataSet
 * This adjusts the x-coordinates of entries, which centers the bars between axis labels
 */
static void groupBars(final BarData barData) {
    IBarDataSet max = barData.getMaxEntryCountSet();
    int maxEntryCount = max.getEntryCount();
    float groupSpaceWidthHalf = GROUP_SPACE / 2f;
    float barWidthHalf = barData.getBarWidth() / 2f;
    float interval = barData.getGroupWidth(GROUP_SPACE, 0);
    float fromX = 0;

    for (int i = 0; i < maxEntryCount; i++) {
        float start = fromX;
        fromX += groupSpaceWidthHalf;

        for (IBarDataSet set : barData.getDataSets()) {
            fromX += barWidthHalf;
            if (i < set.getEntryCount()) {
                BarEntry entry = set.getEntryForIndex(i);
                if (entry != null) {
                    entry.setX(fromX);
                }
            }
            fromX += barWidthHalf;
        }

        fromX += groupSpaceWidthHalf;
        float end = fromX;
        float innerInterval = end - start;
        float diff = interval - innerInterval;

        // correct rounding errors
        if (diff > 0 || diff < 0) {
            fromX += diff;
        }
    }
    barData.notifyDataChanged();
}
 
Example 18
Source File: BarData.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
/**
 * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries.
 * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified
 * by the parameters.
 * Do not forget to call notifyDataSetChanged() on your BarChart object after calling this method.
 *
 * @param fromX      the starting point on the x-axis where the grouping should begin
 * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f
 * @param barSpace   the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f
 */
public void groupBars(float fromX, float groupSpace, float barSpace) {

    int setCount = mDataSets.size();
    if (setCount <= 1) {
        throw new RuntimeException("BarData needs to hold at least 2 BarDataSets to allow grouping.");
    }

    IBarDataSet max = getMaxEntryCountSet();
    int maxEntryCount = max.getEntryCount();

    float groupSpaceWidthHalf = groupSpace / 2f;
    float barSpaceHalf = barSpace / 2f;
    float barWidthHalf = mBarWidth / 2f;

    float interval = getGroupWidth(groupSpace, barSpace);

    for (int i = 0; i < maxEntryCount; i++) {

        float start = fromX;
        fromX += groupSpaceWidthHalf;

        for (IBarDataSet set : mDataSets) {

            fromX += barSpaceHalf;
            fromX += barWidthHalf;

            if (i < set.getEntryCount()) {

                BarEntry entry = set.getEntryForIndex(i);

                if (entry != null) {
                    entry.setX(fromX);
                }
            }

            fromX += barWidthHalf;
            fromX += barSpaceHalf;
        }

        fromX += groupSpaceWidthHalf;
        float end = fromX;
        float innerInterval = end - start;
        float diff = interval - innerInterval;

        // correct rounding errors
        if (diff > 0 || diff < 0) {
            fromX += diff;
        }
    }

    notifyDataChanged();
}
 
Example 19
Source File: BarData.java    From android-kline with Apache License 2.0 4 votes vote down vote up
/**
 * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries.
 * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified
 * by the parameters.
 * Do not forget to call notifyDataSetChanged() on your BarChart object after calling this method.
 *
 * @param fromX      the starting point on the x-axis where the grouping should begin
 * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f
 * @param barSpace   the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f
 */
public void groupBars(float fromX, float groupSpace, float barSpace) {

    int setCount = mDataSets.size();
    if (setCount <= 1) {
        throw new RuntimeException("BarData needs to hold at least 2 BarDataSets to allow grouping.");
    }

    IBarDataSet max = getMaxEntryCountSet();
    int maxEntryCount = max.getEntryCount();

    float groupSpaceWidthHalf = groupSpace / 2f;
    float barSpaceHalf = barSpace / 2f;
    float barWidthHalf = mBarWidth / 2f;

    float interval = getGroupWidth(groupSpace, barSpace);

    for (int i = 0; i < maxEntryCount; i++) {

        float start = fromX;
        fromX += groupSpaceWidthHalf;

        for (IBarDataSet set : mDataSets) {

            fromX += barSpaceHalf;
            fromX += barWidthHalf;

            if (i < set.getEntryCount()) {

                BarEntry entry = set.getEntryForIndex(i);

                if (entry != null) {
                    entry.setX(fromX);
                }
            }

            fromX += barWidthHalf;
            fromX += barSpaceHalf;
        }

        fromX += groupSpaceWidthHalf;
        float end = fromX;
        float innerInterval = end - start;
        float diff = interval - innerInterval;

        // correct rounding errors
        if (diff > 0 || diff < 0) {
            fromX += diff;
        }
    }

    notifyDataChanged();
}
 
Example 20
Source File: BarData.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
/**
 * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries.
 * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified
 * by the parameters.
 * Do not forget to call notifyDataSetChanged() on your BarChart object after calling this method.
 *
 * @param fromX      the starting point on the x-axis where the grouping should begin
 * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f
 * @param barSpace   the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f
 */
public void groupBars(float fromX, float groupSpace, float barSpace) {

    int setCount = mDataSets.size();
    if (setCount <= 1) {
        throw new RuntimeException("BarData needs to hold at least 2 BarDataSets to allow grouping.");
    }

    IBarDataSet max = getMaxEntryCountSet();
    int maxEntryCount = max.getEntryCount();

    float groupSpaceWidthHalf = groupSpace / 2f;
    float barSpaceHalf = barSpace / 2f;
    float barWidthHalf = mBarWidth / 2f;

    float interval = getGroupWidth(groupSpace, barSpace);

    for (int i = 0; i < maxEntryCount; i++) {

        float start = fromX;
        fromX += groupSpaceWidthHalf;

        for (IBarDataSet set : mDataSets) {

            fromX += barSpaceHalf;
            fromX += barWidthHalf;

            if (i < set.getEntryCount()) {

                BarEntry entry = set.getEntryForIndex(i);

                if (entry != null) {
                    entry.setX(fromX);
                }
            }

            fromX += barWidthHalf;
            fromX += barSpaceHalf;
        }

        fromX += groupSpaceWidthHalf;
        float end = fromX;
        float innerInterval = end - start;
        float diff = interval - innerInterval;

        // correct rounding errors
        if (diff > 0 || diff < 0) {
            fromX += diff;
        }
    }

    notifyDataChanged();
}