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

The following examples show how to use com.github.mikephil.charting.data.BarData#setValueFormatter() . 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: StackedBarActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

	tvX.setText("" + (mSeekBarX.getProgress() + 1));
	tvY.setText("" + (mSeekBarY.getProgress()));

	ArrayList<String> xVals = new ArrayList<String>();
	for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
		xVals.add(mMonths[i % mMonths.length]);
	}

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

	for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
		float mult = (mSeekBarY.getProgress() + 1);
		float val1 = (float) (Math.random() * mult) + mult / 3;
		float val2 = (float) (Math.random() * mult) + mult / 3;
		float val3 = (float) (Math.random() * mult) + mult / 3;

		yVals1.add(new BarEntry(new float[] { val1, val2, val3 }, i));
	}

	BarDataSet set1 = new BarDataSet(yVals1, "Statistics Vienna 2014");
	set1.setColors(getColors());
	set1.setStackLabels(new String[] { "Births", "Divorces", "Marriages" });

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

	BarData data = new BarData(xVals, dataSets);
	data.setValueFormatter(new MyValueFormatter());

	mChart.setData(data);
	mChart.invalidate();
}
 
Example 2
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 3
Source File: BarGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void draw(List<BarEntry> entries, ArrayList<String> xAxisLabel) {
    mChart.clear();
    if (entries.isEmpty()) {
        return;
    }

    XAxis xAxis = this.mChart.getXAxis();
    xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisLabel));

    Collections.sort(entries, new EntryXComparator());

    BarDataSet set1 = new BarDataSet(entries, mChartName);
    set1.setColor(mContext.getResources().getColor(R.color.toolbar_background));

    // Create a data object with the datasets
    BarData data = new BarData(set1);

    data.setValueTextSize(12);
    data.setValueFormatter(new IValueFormatter() {
        private DecimalFormat mFormat = new DecimalFormat("#.## kg");

        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return mFormat.format(value);
        }
    });

    // Set data
    mChart.setData(data);

    mChart.getAxisLeft().setAxisMinimum(0f);

    mChart.invalidate();
}
 
Example 4
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();
    }