Java Code Examples for com.github.mikephil.charting.data.BarDataSet#setColors()

The following examples show how to use com.github.mikephil.charting.data.BarDataSet#setColors() . 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: 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 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: 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 5
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 6
Source File: GraphLayout.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * get bar chart data for male/female vocal ranges
 * to display them as bars beneath other chart data
 *
 * @param amount amount of entries needed
 * @return bar data to add to chart
 */
public static BarDataSet getOverallRange(Context context, int amount)
{
    BarDataSet set = new BarDataSet(GraphLayout.getRangeEntries(amount), "");
    set.setDrawValues(false);
    set.setColors(new int[]{context.getResources().getColor(R.color.male_range),
                            context.getResources().getColor(R.color.androgynous_range),
                            context.getResources().getColor(R.color.female_range)});
    set.setStackLabels(new String[]{context.getResources().getString(R.string.male_range),
                                    context.getResources().getString(R.string.androgynous_range),
                                    context.getResources().getString(R.string.female_range)
    });

    //        List<BarDataSet> setList = new ArrayList<BarDataSet>();
    //        setList.add(set);
    //
    //        return setList;

    return set;
}
 
Example 7
Source File: StatisticsFragment.java    From Expense-Tracker-App with MIT License 6 votes vote down vote up
private void setCategoriesBarChart() {
    List<String> categoriesNames = new ArrayList<>();
    List<BarEntry> entryPerCategory = new ArrayList<>();

    for (int i=0; i < mCategoryList.size(); i++) {
        float value = Expense.getCategoryTotalByDate(DateManager.getInstance().getDateFrom(), DateManager.getInstance().getDateTo(), mCategoryList.get(i));
        if (value > 0) {
            categoriesNames.add(mCategoryList.get(i).getName());
            entryPerCategory.add(new BarEntry(value, categoriesNames.size()-1));
        }
    }
    if (categoriesNames.isEmpty()) {
        tvBcCategoriesEmpty.setVisibility(View.VISIBLE);
        bcCategories.setVisibility(View.GONE);
    } else {
        tvBcCategoriesEmpty.setVisibility(View.GONE);
        bcCategories.setVisibility(View.VISIBLE);
    }
    BarDataSet dataSet = new BarDataSet(entryPerCategory, getString(R.string.categories));
    dataSet.setColors(Util.getListColors());
    BarData barData = new BarData(categoriesNames, dataSet);
    bcCategories.setData(barData);
    bcCategories.invalidate();
}
 
Example 8
Source File: ListViewMultiChartActivity.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 generateDataBar(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.setHighLightAlpha(255);
    
    BarData cd = new BarData(getMonths(), d);
    return cd;
}
 
Example 9
Source File: ListViewMultiChartActivity.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 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 10
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 11
Source File: SimpleFragment.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
protected BarData generateBarData(int dataSets, float range, int count) {

        ArrayList<IBarDataSet> sets = new ArrayList<>();

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

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

            for(int j = 0; j < count; j++) {
                entries.add(new BarEntry(j, (float) (Math.random() * range) + range / 4));
            }

            BarDataSet ds = new BarDataSet(entries, getLabel(i));
            ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
            sets.add(ds);
        }

        BarData d = new BarData(sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example 12
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 13
Source File: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private BarData generateBarData() {

        ArrayList<BarEntry> entries1 = new ArrayList<>();
        ArrayList<BarEntry> entries2 = new ArrayList<>();

        for (int index = 0; index < count; index++) {
            entries1.add(new BarEntry(0, getRandom(25, 25)));

            // stacked
            entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)}));
        }

        BarDataSet set1 = new BarDataSet(entries1, "Bar 1");
        set1.setColor(Color.rgb(60, 220, 78));
        set1.setValueTextColor(Color.rgb(60, 220, 78));
        set1.setValueTextSize(10f);
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);

        BarDataSet set2 = new BarDataSet(entries2, "");
        set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
        set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255));
        set2.setValueTextColor(Color.rgb(61, 165, 255));
        set2.setValueTextSize(10f);
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);

        float groupSpace = 0.06f;
        float barSpace = 0.02f; // x2 dataset
        float barWidth = 0.45f; // x2 dataset
        // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"

        BarData d = new BarData(set1, set2);
        d.setBarWidth(barWidth);

        // make this BarData object grouped
        d.groupBars(0, groupSpace, barSpace); // start at x = 0

        return d;
    }
 
Example 14
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 15
Source File: FreeHandView.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
public BarData updateBarEntry() {
    ArrayList<BarEntry> mBarEntry = new ArrayList<>();
    for (int j = 0; j < 10; ++j) {
        mBarEntry.add(new BarEntry(j, mClassifier.getProbability(j)));
    }
    BarDataSet mBarDataSet = new BarDataSet(mBarEntry, "Projects");
    mBarDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
    BarData mBardData = new BarData(mBarDataSet);
    return mBardData;
}
 
Example 16
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 17
Source File: CurrentDayFragment.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * date: 2019/2/21
 * author: chenli
 * description: 生成成交量数据集
 */
private BarDataSet generateBarDataSet(List<BarEntry> entries, String label, boolean isHighlight, int... colors) {
    BarDataSet set = new BarDataSet(entries, label);
    set.setColors(colors);
    set.setBarBorderWidth(0);
    set.setDrawValues(false);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    if (isHighlight) {
        set.setHighLightColor(mHighlightColor);
    } else {
        set.setHighlightEnabled(false);
    }
    return set;
}
 
Example 18
Source File: AnotherBarActivity.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<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;
        yVals1.add(new BarEntry((int) val1, i));
    }

    ArrayList<String> xVals = new ArrayList<String>();
    for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
        xVals.add((int) yVals1.get(i).getVal() + "");
    }

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

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

    BarData data = new BarData(xVals, dataSets);

    mChart.setData(data);
    mChart.invalidate();
}
 
Example 19
Source File: ChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private ArrayList<BarDataSet> getDataSet() {
    ArrayList<BarDataSet> dataSets = null;

    ArrayList<BarEntry> valueSet1 = new ArrayList<>();
    BarEntry v1e1 = new BarEntry(110.000f, 0); // Jan
    valueSet1.add(v1e1);
    BarEntry v1e2 = new BarEntry(40.000f, 1); // Feb
    valueSet1.add(v1e2);
    BarEntry v1e3 = new BarEntry(60.000f, 2); // Mar
    valueSet1.add(v1e3);
    BarEntry v1e4 = new BarEntry(30.000f, 3); // Apr
    valueSet1.add(v1e4);
    BarEntry v1e5 = new BarEntry(90.000f, 4); // May
    valueSet1.add(v1e5);
    BarEntry v1e6 = new BarEntry(100.000f, 5); // Jun
    valueSet1.add(v1e6);

    ArrayList<BarEntry> valueSet2 = new ArrayList<>();
    BarEntry v2e1 = new BarEntry(150.000f, 0); // Jan
    valueSet2.add(v2e1);
    BarEntry v2e2 = new BarEntry(90.000f, 1); // Feb
    valueSet2.add(v2e2);
    BarEntry v2e3 = new BarEntry(120.000f, 2); // Mar
    valueSet2.add(v2e3);
    BarEntry v2e4 = new BarEntry(60.000f, 3); // Apr
    valueSet2.add(v2e4);
    BarEntry v2e5 = new BarEntry(20.000f, 4); // May
    valueSet2.add(v2e5);
    BarEntry v2e6 = new BarEntry(80.000f, 5); // Jun
    valueSet2.add(v2e6);

    BarDataSet barDataSet1 = new BarDataSet(valueSet1, "Brand 1");
    barDataSet1.setColor(Color.rgb(0, 155, 0));
    BarDataSet barDataSet2 = new BarDataSet(valueSet2, "Brand 2");
    barDataSet2.setColors(ColorTemplate.COLORFUL_COLORS);

    dataSets = new ArrayList<>();
    dataSets.add(barDataSet1);
    dataSets.add(barDataSet2);
    return dataSets;
}
 
Example 20
Source File: StackedBarActivityNegative.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_age_distribution);

    setTitle("Age Distribution Austria");

    mChart = (HorizontalBarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.setDescription("");

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setAxisMaxValue(25f);
    mChart.getAxisRight().setAxisMinValue(-25f);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getAxisRight().setDrawZeroLine(true);
    mChart.getAxisRight().setLabelCount(7, false);
    mChart.getAxisRight().setValueFormatter(new CustomFormatter());
    mChart.getAxisRight().setTextSize(9f);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);

    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
    yValues.add(new BarEntry(new float[]{ -10, 10 }, 0));
    yValues.add(new BarEntry(new float[]{ -12, 13 }, 1));
    yValues.add(new BarEntry(new float[]{ -15, 15 }, 2));
    yValues.add(new BarEntry(new float[]{ -17, 17 }, 3));
    yValues.add(new BarEntry(new float[]{ -19, 20 }, 4));
    yValues.add(new BarEntry(new float[]{ -19, 19 }, 5));
    yValues.add(new BarEntry(new float[]{ -16, 16 }, 6));
    yValues.add(new BarEntry(new float[]{ -13, 14 }, 7));
    yValues.add(new BarEntry(new float[]{ -10, 11 }, 8));
    yValues.add(new BarEntry(new float[]{ -5, 6 }, 9));
    yValues.add(new BarEntry(new float[]{ -1, 2 }, 10));

    BarDataSet set = new BarDataSet(yValues, "Age Distribution");
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setBarSpacePercent(40f);
    set.setColors(new int[] {Color.rgb(67,67,72), Color.rgb(124,181,236)});
    set.setStackLabels(new String[]{
            "Men", "Women"
    });

    String []xVals = new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+"};

    BarData data = new BarData(xVals, set);
    mChart.setData(data);
    mChart.invalidate();
}