com.github.mikephil.charting.data.BarData Java Examples

The following examples show how to use com.github.mikephil.charting.data.BarData. 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: BarHighlighter.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
@Override
protected SelectionDetail getSelectionDetail(int xIndex, float y, int dataSetIndex) {

	dataSetIndex = Math.max(dataSetIndex, 0);

	BarData barData = mChart.getBarData();
	IDataSet dataSet = barData.getDataSetCount() > dataSetIndex
			? barData.getDataSetByIndex(dataSetIndex)
			: null;
	if (dataSet == null)
		return null;

	final float yValue = dataSet.getYValForXIndex(xIndex);

	if (yValue == Double.NaN) return null;

	return new SelectionDetail(
			yValue,
			dataSetIndex,
			dataSet);
}
 
Example #2
Source File: ListViewBarChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private BarData generateData(int cnt) {

    ArrayList<BarEntry> entries = new ArrayList<BarEntry>();

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);    
    d.setBarSpacePercent(20f);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setBarShadowColor(Color.rgb(203, 203, 203));
    
    ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
    sets.add(d);
    
    BarData cd = new BarData(getMonths(), sets);
    return cd;
}
 
Example #3
Source File: SimpleFragment.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected BarData generateBarData(int dataSets, float range, int count) {
        
        ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
        
        for(int i = 0; i < dataSets; i++) {
           
            ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
            
//            entries = FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "stacked_bars.txt");
            
            for(int j = 0; j < count; j++) {        
                entries.add(new BarEntry((float) (Math.random() * range) + range / 4, j));
            }
            
            BarDataSet ds = new BarDataSet(entries, getLabel(i));
            ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
            sets.add(ds);
        }
        
        BarData d = new BarData(ChartData.generateXVals(0, count), sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #4
Source File: ScrollViewActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData(int count) {
    
    ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
    ArrayList<String> xVals = new ArrayList<String>();

    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * count) + 15;
        yVals.add(new BarEntry((int) val, i));
        xVals.add((int) val + "");
    }

    BarDataSet set = new BarDataSet(yVals, "Data Set");
    set.setColors(ColorTemplate.VORDIPLOM_COLORS);
    set.setDrawValues(false);

    BarData data = new BarData(xVals, set);

    mChart.setData(data);
    mChart.invalidate();
    mChart.animateY(800);
}
 
Example #5
Source File: StatisticActivity.java    From memorize with MIT License 6 votes vote down vote up
private BarData generateDataBar(int cnt) {

        ArrayList<BarEntry> entries = new ArrayList<>();

        for (int i = 0; i < 12; i++) {
            entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
        }

        BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
        d.setColors(ColorTemplate.VORDIPLOM_COLORS);
        d.setHighLightAlpha(255);

        BarData cd = new BarData(d);
        cd.setBarWidth(0.9f);
        return cd;
    }
 
Example #6
Source File: OneDayChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 动态增加一个点数据
 * @param timeDatamodel
 * @param length
 */
public void dynamicsAddOne(TimeDataModel timeDatamodel, int length) {
    int index = length - 1;
    LineData lineData = lineChart.getData();
    ILineDataSet d1 = lineData.getDataSetByIndex(0);
    d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice()));
    ILineDataSet d2 = lineData.getDataSetByIndex(1);
    d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice()));

    BarData barData = barChart.getData();
    IBarDataSet barDataSet = barData.getDataSetByIndex(0);
    float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f;
    barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color));
    lineData.notifyDataChanged();
    lineChart.notifyDataSetChanged();
    barData.notifyDataChanged();
    barChart.notifyDataSetChanged();
    lineChart.setVisibleXRange(maxCount, maxCount);
    barChart.setVisibleXRange(maxCount, maxCount);
    //动态添加或移除数据后, 调用invalidate()刷新图表之前 必须调用 notifyDataSetChanged() .
    lineChart.moveViewToX(index);
    barChart.moveViewToX(index);
}
 
Example #7
Source File: BarHighlighter.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {
    Highlight high = super.getHighlight(x, y);

    if(high == null) {
        return null;
    }

    MPPointD pos = getValsForTouch(x, y);

    BarData barData = mChart.getBarData();

    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {

        return getStackedHighlight(high,
                set,
                (float) pos.x,
                (float) pos.y);
    }

    MPPointD.recycleInstance(pos);

    return high;
}
 
Example #8
Source File: ListViewBarChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Bar data
 */
private BarData generateData(int cnt) {

    ArrayList<BarEntry> entries = new ArrayList<>();

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setBarShadowColor(Color.rgb(203, 203, 203));

    ArrayList<IBarDataSet> sets = new ArrayList<>();
    sets.add(d);

    BarData cd = new BarData(sets);
    cd.setBarWidth(0.9f);
    return cd;
}
 
Example #9
Source File: ScrollViewActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private void setData(int count) {

        ArrayList<BarEntry> values = new ArrayList<>();

        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * count) + 15;
            values.add(new BarEntry(i, (int) val));
        }

        BarDataSet set = new BarDataSet(values, "Data Set");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setDrawValues(false);

        BarData data = new BarData(set);

        chart.setData(data);
        chart.invalidate();
        chart.animateY(800);
    }
 
Example #10
Source File: BarHighlighter.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {
    Highlight high = super.getHighlight(x, y);

    if(high == null) {
        return null;
    }

    MPPointD pos = getValsForTouch(x, y);

    BarData barData = mChart.getBarData();

    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {

        return getStackedHighlight(high,
                set,
                (float) pos.x,
                (float) pos.y);
    }

    MPPointD.recycleInstance(pos);

    return high;
}
 
Example #11
Source File: HorizontalBarHighlighter.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

	BarData barData = mChart.getBarData();

	MPPointD pos = getValsForTouch(y, x);

	Highlight high = getHighlightForX((float) pos.y, y, x);
	if (high == null)
		return null;

	IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
	if (set.isStacked()) {

		return getStackedHighlight(high,
				set,
				(float) pos.y,
				(float) pos.x);
	}

	MPPointD.recycleInstance(pos);

	return high;
}
 
Example #12
Source File: HistogramChart.java    From walt with Apache License 2.0 6 votes vote down vote up
void recalculateDataSet(final BarData barData) {
    minBin = Math.floor(min / binWidth) * binWidth;
    maxBin = Math.floor(max / binWidth) * binWidth;

    int[][] bins = new int[rawData.size()][getNumBins()];

    for (int setNum = 0; setNum < rawData.size(); setNum++) {
        for (Double d : rawData.get(setNum)) {
            ++bins[setNum][(int) (Math.floor((d - minBin) / binWidth))];
        }
    }

    for (int setNum = 0; setNum < barData.getDataSetCount(); setNum++) {
        final IBarDataSet dataSet = barData.getDataSetByIndex(setNum);
        dataSet.clear();
        for (int i = 0; i < bins[setNum].length; i++) {
            dataSet.addEntry(new BarEntry(i, bins[setNum][i]));
        }
    }
    groupBars(barData);
    barData.notifyDataChanged();
}
 
Example #13
Source File: ProductDetailActivity.java    From FaceT with Mozilla Public License 2.0 6 votes vote down vote up
public BarData getBarData() {

        ArrayList<BarEntry> entries = new ArrayList<>();
        float overall_people = 100f;

        Log.d(TAG + "barData", barRatingCount[3] + "");
        entries.add(new BarEntry(4, barRatingCount[4]));
        entries.add(new BarEntry(3, barRatingCount[3]));
        entries.add(new BarEntry(2, barRatingCount[2]));
        entries.add(new BarEntry(1, barRatingCount[1]));
        entries.add(new BarEntry(0, barRatingCount[0]));

        BarDataSet dataset = new BarDataSet(entries, "");
        dataset.setColors(CUSTOM_COLOR);
        dataset.setDrawValues(false);

        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(dataset);

        BarData data = new BarData(dataSets);
//        data.setValueTextSize(10f);
//        data.setValueTypeface(fontType);
        data.setBarWidth(1f);

        return data;
    }
 
Example #14
Source File: BarHighlighter.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {
    Highlight high = super.getHighlight(x, y);

    if(high == null) {
        return null;
    }

    MPPointD pos = getValsForTouch(x, y);

    BarData barData = mChart.getBarData();

    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {

        return getStackedHighlight(high,
                set,
                (float) pos.x,
                (float) pos.y);
    }

    MPPointD.recycleInstance(pos);

    return high;
}
 
Example #15
Source File: HorizontalBarHighlighter.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

	BarData barData = mChart.getBarData();

	MPPointD pos = getValsForTouch(y, x);

	Highlight high = getHighlightForX((float) pos.y, y, x);
	if (high == null)
		return null;

	IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
	if (set.isStacked()) {

		return getStackedHighlight(high,
				set,
				(float) pos.y,
				(float) pos.x);
	}

	MPPointD.recycleInstance(pos);

	return high;
}
 
Example #16
Source File: BarChartActivity.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 生成柱状图的数据
 */
private BarData generateDataBar() {

    ArrayList<BarEntry> entries = new ArrayList<BarEntry>();

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet ");
    // 设置柱状图之间的间距
    d.setBarSpacePercent(20f);
    // 设置显示的柱状图的颜色
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    // 设置高亮的透明度:当点击柱状图时显示的透明度
    d.setHighLightAlpha(255);

    BarData cd = new BarData(getMonths(), d);
    return cd;
}
 
Example #17
Source File: StatisticsFragment.java    From HeartBeat with Apache License 2.0 6 votes vote down vote up
private BarData getWeekEventData() {
    BarData d = new BarData();

    ArrayList<BarEntry> entries = new ArrayList<>();

    for (int i=0; i<WEEK_COUNT; i++) {
        entries.add(
                new BarEntry(
                        new GetCountSpecDayApi(getActivity()).exec(
                                TimeUtils.calendarDaysBefore(WEEK_COUNT-i),
                                GetCountSpecDayApi.EVENT
                        ),i
                )
        );
    }

    BarDataSet set = new BarDataSet(entries, getString(R.string.event_count_text));
    set.setColor(mPrimaryColorDark);
    set.setValueFormatter(new IntValueFormatter());
    d.addDataSet(set);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    return d;
}
 
Example #18
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 #19
Source File: BarChartRenderer.java    From iMoney 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++) {

        BarDataSet set = barData.getDataSetByIndex(i);

        if (set.isVisible() && set.getEntryCount() > 0) {
            drawDataSet(c, set, i);
        }
    }
}
 
Example #20
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 #21
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 #22
Source File: BarChartPositiveNegative.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private void setData(List<Data> dataList) {

        ArrayList<BarEntry> values = new ArrayList<BarEntry>();
        String[] dates = new String[dataList.size()];
        List<Integer> colors = new ArrayList<Integer>();

        int green = Color.rgb(110, 190, 102);
        int red = Color.rgb(211, 74, 88);

        for (int i = 0; i < dataList.size(); i++) {

            Data d = dataList.get(i);
            BarEntry entry = new BarEntry(d.yValue, d.xIndex);
            values.add(entry);

            dates[i] = dataList.get(i).xAxisValue;

            // specific colors
            if (d.yValue >= 0)
                colors.add(red);
            else
                colors.add(green);
        }

        BarDataSet set = new BarDataSet(values, "Values");
        set.setBarSpacePercent(40f);
        set.setColors(colors);
        set.setValueTextColors(colors);

        BarData data = new BarData(dates, set);
        data.setValueTextSize(13f);
        data.setValueTypeface(mTf);
        data.setValueFormatter(new ValueFormatter());

        mChart.setData(data);
        mChart.invalidate();
    }
 
Example #23
Source File: ExpenseDetailFragment.java    From Expense-Tracker-App with MIT License 5 votes vote down vote up
private void setWeekChart() {
    List<Date> dateList = DateUtils.getWeekDates();
    List<String> days = new ArrayList<>();
    Collections.sort(dateList);

    List<BarEntry> entriesPerDay = new ArrayList<>();

    for (int i=0; i < dateList.size(); i++) {
        Date date = dateList.get(i);
        String day = Util.formatDateToString(date, "EEE");
        float value = Expense.getCategoryTotalByDate(date, expense.getCategory());
        days.add(day);
        entriesPerDay.add(new BarEntry(value, i));
    }
    BarDataSet dataSet = new BarDataSet(entriesPerDay, getString(R.string.this_week));
    dataSet.setColors(Util.getListColors());
    BarData barData = new BarData(days, dataSet);
    bcWeekExpenses.setVisibleXRangeMaximum(5);
    bcWeekExpenses.getAxisLeft().setDrawGridLines(false);
    bcWeekExpenses.getXAxis().setDrawGridLines(false);
    bcWeekExpenses.getAxisRight().setDrawGridLines(false);
    bcWeekExpenses.getAxisRight().setDrawLabels(false);
    bcWeekExpenses.setData(barData);
    bcWeekExpenses.setDescription("");
    bcWeekExpenses.animateY(2000);
    bcWeekExpenses.invalidate();
}
 
Example #24
Source File: Results.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void setDataS() {

        ArrayList<String> xVals = new ArrayList<String>();
        Collections.addAll(xVals, ltob);


        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

        for (int i = 0; i < splHistogram.size(); i++) {
            yVals1.add(new BarEntry(splHistogram.get(i), i));
        }

        BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
        set1.setValueTextColor(Color.WHITE);

        set1.setColors(
                new int[]{Color.rgb(0, 128, 255), Color.rgb(0, 128, 255), Color.rgb(0, 128, 255),
                        Color.rgb(102, 178, 255), Color.rgb(102, 178, 255),
                        Color.rgb(102, 178, 255)});

        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);
        data.setValueFormatter(new FreqValueFormater(sChart));
        sChart.setData(data);
        sChart.invalidate();
    }
 
Example #25
Source File: DailyBarChart.java    From AndroidApp with GNU Affero General Public License v3.0 5 votes vote down vote up
private BarData createDataSet() {
    ArrayList<BarEntry> entries = new ArrayList<>();
    BarData chart2_bardata = new BarData();
    BarDataSet chart2_dataset = new BarDataSet(entries, "kWh");
    chart2_dataset.setColor(ContextCompat.getColor(context, R.color.colorAccent));
    chart2_dataset.setValueTextColor(ContextCompat.getColor(context, R.color.lightGrey));
    chart2_dataset.setValueTextSize(context.getResources().getInteger(R.integer.chartValueTextSize));
    chart2_dataset.setValueFormatter(new Chart2ValueFormatter());
    chart2_bardata.addDataSet(chart2_dataset);
    barChart.setData(chart2_bardata);
    return chart2_bardata;
}
 
Example #26
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 #27
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 #28
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 #29
Source File: BarChartRenderer.java    From Ticket-Analysis with MIT License 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()) {
            drawDataSet(c, set, i);
        }
    }
}
 
Example #30
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;
}