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

The following examples show how to use com.github.mikephil.charting.data.BarData#setValueTextSize() . 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: BarChartActivitySinus.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData(int count) {

        ArrayList<String> xVals = new ArrayList<String>();
        
        ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
        
        for (int i = 0; i < count; i++) {
            xVals.add(i+"");
            entries.add(mSinusData.get(i));
        }
        
        BarDataSet set = new BarDataSet(entries, "Sinus Function");
        set.setBarSpacePercent(40f);
        set.setColor(Color.rgb(240, 120, 124));

        BarData data = new BarData(xVals, set);
        data.setValueTextSize(10f);
        data.setValueTypeface(mTf);
        data.setDrawValues(false);

        mChart.setData(data);
    }
 
Example 2
Source File: HorizontalBarChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            xVals.add(mMonths[i % 12]);
            yVals1.add(new BarEntry((float) (Math.random() * range), i));
        }

        BarDataSet set1 = new BarDataSet(yVals1, "DataSet 1");

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

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(tf);

        mChart.setData(data);
    }
 
Example 3
Source File: MeasurementActivity.java    From NoiseCapture with GNU General Public License v3.0 6 votes vote down vote up
private void setData(double val) {

        ArrayList<String> xVals = new ArrayList<String>();
        xVals.add("");

        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
        yVals1.add(new BarEntry((float)val, 0));

        BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
        //set1.setBarSpacePercent(35f);
        //set1.setColor(Color.rgb(0, 153, 204));
        int nc=getNEcatColors(val);    // Choose the color category in function of the sound level
        set1.setColor(NE_COLORS[nc]);

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

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);

        mChart.setData(data);
        mChart.invalidate(); // refresh
    }
 
Example 4
Source File: BarChartActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private void setData(int count, float range) {

        ArrayList<String> xVals = new ArrayList<String>();
        for (int i = 0; i < count; i++) {
            xVals.add(mMonths[i % 12]);
        }

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

        for (int i = 0; i < count; i++) {
            float mult = (range + 1);
            float val = (float) (Math.random() * mult);
            yVals1.add(new BarEntry(val, i));
        }

        BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
        set1.setBarSpacePercent(35f);

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

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(mTf);

        mChart.setData(data);
    }
 
Example 5
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 6
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 7
Source File: AnalysisFragment.java    From outlay with Apache License 2.0 5 votes vote down vote up
@Override
public void showAnalysis(Report report) {
    List<BarEntry> barEntries = new ArrayList<>();
    List<Expense> expenses = report.getExpenses();

    for (int i = 0; i < expenses.size(); i++) {
        Expense expense = expenses.get(i);
        barEntries.add(new BarEntry(
                i,
                expense.getAmount().floatValue())
        );
    }
    BarDataSet barSet = new BarDataSet(barEntries, "");
    barSet.setColor(selectedCategory.getColor());

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

    BarData data = new BarData(dataSets);
    data.setValueTextSize(10f);
    data.setValueTextColor(getOutlayTheme().secondaryTextColor);
    data.setBarWidth(0.9f);

    dayAxisValueFormatter.setExpenses(expenses);
    barChart.setData(data);
    barChart.invalidate();
    barChart.animateY(500);
}
 
Example 8
Source File: MeasurementActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void updateSpectrumGUI() {


        ArrayList<String> xVals = new ArrayList<String>();
        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
        double[] freqLabels = measurementService.getAudioProcess().getRealtimeCenterFrequency();
        float[] freqValues = measurementService.getAudioProcess().getThirdOctaveFrequencySPL();
        for(int idfreq =0; idfreq < freqLabels.length; idfreq++) {
            xVals.add(Spectrogram.formatFrequency((int)freqLabels[idfreq]));
            // Sum values
            // Compute frequency range covered by frequency
            yVals1.add(new BarEntry(new float[] {freqValues[idfreq]}, idfreq));
        }

        BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
        set1.setColor(Color.rgb(102, 178, 255));
        set1.setStackLabels(new String[]{
                "SL"
        });

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

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);

        BarChart sChart = getSpectrum();
        if(sChart != null){
            sChart.setData(data);
            sChart.setPadding(0, 0, 0, 0);
            sChart.setViewPortOffsets(0,0,0,0);
            sChart.invalidate(); // refresh
        }
    }
 
Example 9
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 10
Source File: FragmentTimeBarChart.java    From fingen with Apache License 2.0 4 votes vote down vote up
private void setData(List<DateEntry> entries) {
        ReportBuilder reportBuilder = ReportBuilder.getInstance(getActivity());
        if (entries.size() == 0) {
            mBarChart.clear();
            return;
        }
        Pair<ArrayList<IBarDataSet>, ArrayList<String>> pair;
        switch (reportBuilder.getActiveShowIndex()) {
            case ReportBuilder.SHOW_INCOME_AND_EXPENSE:
                pair = getDatasetsInAndEx(entries);
                break;
            case ReportBuilder.SHOW_INCOME_MINUS_EXPENSE:
                pair = getDatasetsInMinusEx(entries);
                break;
            case ReportBuilder.SHOW_INCOME:
                pair = getDatasetsSingle(entries, false);
                break;
            case ReportBuilder.SHOW_EXPENSE:
                pair = getDatasetsSingle(entries, true);
                break;
            default:
                return;
        }

        if (pair.second.size() == 0) {
            mBarChart.clear();
            return;
        }

        BarData data = new BarData(pair.second, pair.first);
        data.setValueTextSize(10f);
        data.setGroupSpace(80f);
//        data.setValueTypeface(tf);

        mBarChart.setData(data);
        mBarChart.fitScreen();
        mBarChart.animateY(1000);
        mBarChart.highlightValues(null);

        if (mBarChart.getHighlighted() == null) {
            mFabLayout.setVisibility(View.GONE);
        } else {
            mFabLayout.setVisibility(View.VISIBLE);
        }
    }
 
Example 11
Source File: FragmentBarChart.java    From fingen with Apache License 2.0 4 votes vote down vote up
private void setData(BaseNode tree) {
        ReportBuilder reportBuilder = ReportBuilder.getInstance(getActivity());
        if (tree.getChildren().size() == 0) {
            mBarChart.clear();
            return;
        }

        Pair<ArrayList<IBarDataSet>, ArrayList<String>> pair;
        switch (reportBuilder.getActiveShowIndex()) {
            case ReportBuilder.SHOW_INCOME_AND_EXPENSE:
                pair = getDatasetsInAndEx(tree);
                break;
            case ReportBuilder.SHOW_INCOME_MINUS_EXPENSE:
                pair = getDatasetsInMinusEx(tree);
                break;
            case ReportBuilder.SHOW_INCOME:
                pair = getDatasetsSingle(tree, false);
                break;
            case ReportBuilder.SHOW_EXPENSE:
                pair = getDatasetsSingle(tree, true);
                break;
            default:
                return;
        }

        if (pair.second.size() == 0) {
            mBarChart.clear();
            return;
        }

        BarData data = new BarData(pair.second, pair.first);
        data.setValueTextSize(10f);
        data.setGroupSpace(80f);
//        data.setValueTypeface(tf);

        mBarChart.setData(data);
        mBarChart.fitScreen();
        mBarChart.animateY(1000);
        mBarChart.highlightValues(null);

        if (mBarChart.getHighlighted() == null) {
            mFabLayout.setVisibility(View.GONE);
        } else {
            mFabLayout.setVisibility(View.VISIBLE);
        }
    }