Java Code Examples for com.github.mikephil.charting.data.BarDataSet

The following are top voted examples for showing how to use com.github.mikephil.charting.data.BarDataSet. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Stayfit   File: SimpleFragment.java   View source code 8 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 2
Project: MobileProjectManagement   File: TimeVisualization.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.timevis_layout);

    barchart = (BarChart) findViewById(R.id.barchart);

    Intent intent = getIntent();
    String ot = intent.getExtras().getString("ot");
    String pt = intent.getExtras().getString("pt");
    String lt = intent.getExtras().getString("lt");
    String pert = intent.getExtras().getString("pert");


    Float otf = Float.valueOf(ot);
    Float ptf = Float.valueOf(pt);
    Float ltf = Float.valueOf(lt);
    Float pertf = Float.valueOf(pert);


    List<BarEntry> entries = new ArrayList<>();
    entries.add(new BarEntry(0f, otf.floatValue()));
    entries.add(new BarEntry(1f, ptf.floatValue()));
    entries.add(new BarEntry(2f, ltf.floatValue()));
    entries.add(new BarEntry(3f, pertf.floatValue()));


    BarDataSet set = new BarDataSet(entries, "Time Visualization");
    BarData data = new BarData(set);
    data.setBarWidth(0.9f); // set custom bar width
    barchart.setData(data);
    barchart.setFitBars(true); // make the x-axis fit exactly all bars
    barchart.invalidate();


}
 
Example 3
Project: GitHub   File: SimpleFragment.java   View source code 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(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 4
Project: GitHub   File: ListViewBarChartActivity.java   View source code 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(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<IBarDataSet>();
    sets.add(d);
    
    BarData cd = new BarData(sets);
    cd.setBarWidth(0.9f);
    return cd;
}
 
Example 5
Project: GitHub   File: ListViewMultiChartActivity.java   View source code 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(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
Project: GitHub   File: ScrollViewActivity.java   View source code 6 votes vote down vote up
private void setData(int count) {
    
    ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();

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

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

    BarData data = new BarData(set);

    mChart.setData(data);
    mChart.invalidate();
    mChart.animateY(800);
}
 
Example 7
Project: CodeWatch   File: ProjectDetailsFragment.java   View source code 6 votes vote down vote up
private BarData generateBarData(List<Integer> progressSoFar) {

        ArrayList<BarEntry> barEntries = new ArrayList<>(progressSoFar.size());

        DateTime dateTime = new DateTime();
        referenceTime = dateTime.minusDays(7).getMillis();
        int totalSeconds = 0;
        for (int i = 0; i < progressSoFar.size(); i++) {
            int progress = progressSoFar.get(i);
            barEntries.add(new BarEntry(i, progress));
            totalSeconds += progress;
        }

        activityTotal.setText(context.getString(R.string.total_project_time,
                FormatUtils.getFormattedTime(context, totalSeconds)));

        BarDataSet barDataSet = new BarDataSet(barEntries, "");

        barDataSet.setColors(blue400);

        BarData barData = new BarData(barDataSet);
        barData.setBarWidth(0.85f);
        barData.setDrawValues(false);
        return barData;
    }
 
Example 8
Project: CodeWatch   File: GoalsDetailFragment.java   View source code 6 votes vote down vote up
private BarData generateBarData(int dailyGoal, List<Integer> progressSoFar) {


        ArrayList<BarEntry> barEntries = new ArrayList<>(progressSoFar.size());

        DateTime dateTime = new DateTime();
        referenceTime = dateTime.minusDays(7).getMillis();
        for (int i = 0; i < progressSoFar.size(); i++) {
            barEntries.add(new BarEntry(i, progressSoFar.get(i)));
        }

        BarDataSet barDataSet = new BarDataSet(barEntries, "");

        int colors[] = new int[progressSoFar.size()];
        for (int i = 0; i < progressSoFar.size(); i++) {
            colors[i] = (progressSoFar.get(i) >= dailyGoal * 60 * 60) ? green400 : red400;
        }
        barDataSet.setColors(colors);

        BarData barData = new BarData(barDataSet);
        barData.setBarWidth(0.85f);
        barData.setDrawValues(false);
        return barData;
    }
 
Example 9
Project: Custom-Vison-Service   File: NutritionActivity.java   View source code 6 votes vote down vote up
public void prepareChartData(Hit hit){
        entries = new ArrayList<BarEntry>();
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);

        entries.add(new BarEntry(0, (float) (hit.getFields().getNfCalories()/2000)*100));
        entries.add(new BarEntry(1, (float) (hit.getFields().getNfTotalFat()/65)*100));
        entries.add(new BarEntry(2, (float) (hit.getFields().getNfCholesterol()/300)*100));
        entries.add(new BarEntry(3, (float)(hit.getFields().getNfSodium()/2400)*100));
        entries.add(new BarEntry(4, (float)(hit.getFields().getNfTotalCarbohydrate()/300)*100));
        entries.add(new BarEntry(5, (float) hit.getFields().getNfSodium()));
        entries.add(new BarEntry(6, (float) (hit.getFields().getNfProtein()/50)*100));
//        entries.add(new BarEntry(7, (float) hit.getFields().getNfVitaminADv(), "(mg)"));
//        entries.add(new BarEntry(8, (float) hit.getFields().getNfVitaminCDv(), "(mg)"));
//        entries.add(new BarEntry(9, (float) hit.getFields().getNfCalciumDv(), "(mg)"));

        BarDataSet dataSet = new BarDataSet(entries, String.format("%s Nutrition", food_item).toUpperCase());

        setChartData(dataSet);
    }
 
Example 10
Project: shengyiplus-android   File: HomeTricsActivity.java   View source code 6 votes vote down vote up
/**
 * 柱形图数据
 */
private BarData generateBarData() {
    BarData barData = new BarData();
    ArrayList<BarEntry> entries1 = new ArrayList<>();
    for (int index = 0; index < items.size(); index++) {
        entries1.add(new BarEntry(index + 1f, (float) items.get(index).main_data.getData()));
    }
    BarDataSet barDataSet = new BarDataSet(entries1, "当前数据");
    barDataSet.setValues(entries1);
    barDataSet.setDrawValues(false);//是否在线上显示值
    barDataSet.setColor(Color.rgb(230, 230, 230));
    barDataSet.setHighLightColor(Color.parseColor(items.get(dateSelected).state.getColor()));
    barDataSet.setValueTextColor(Color.rgb(60, 220, 78));
    barDataSet.setValueTextSize(10f);
    barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    float barWidth = 0.45f;
    barData.addDataSet(barDataSet);
    barData.setBarWidth(barWidth);
    return barData;
}
 
Example 11
Project: Stayfit   File: ListViewBarChartActivity.java   View source code 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 12
Project: Stayfit   File: ListViewMultiChartActivity.java   View source code 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 13
Project: Stayfit   File: ScrollViewActivity.java   View source code 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 14
Project: Stayfit   File: HorizontalBarChartActivity.java   View source code 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 15
Project: MarketBot   File: MarketHistoryTab.java   View source code 6 votes vote down vote up
private BarData generateOrderBarData(List<MarketHistory> historyEntries) {

        SimpleDateFormat format = new SimpleDateFormat("MMM dd", Locale.getDefault());

        int size = historyEntries.size();
        List<BarEntry> entries = new ArrayList<>(size);
        List<String> xAxis = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            MarketHistory history = historyEntries.get(i);
            Date recordDate = new Date(history.getRecordDate());

            xAxis.add(format.format(recordDate));
            entries.add(new BarEntry((float) history.getOrderCount(), i));
        }

        BarDataSet set = new BarDataSet(entries, "Order Count");
        set.setColor(Color.parseColor("#99FF99"));
//        set.setValueTextSize(0f);

        set.setDrawValues(false);

        set.setAxisDependency(YAxis.AxisDependency.RIGHT);
        return new BarData(xAxis, set);
    }
 
Example 16
Project: P2P   File: BarChart.java   View source code 6 votes vote down vote up
/**
 * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be
 * found in the charts data.
 * 
 * @param e
 * @return
 */
public RectF getBarBounds(BarEntry e) {

	BarDataSet set = mData.getDataSetForEntry(e);

	if (set == null)
		return null;

	float barspace = set.getBarSpace();
	float y = e.getVal();
	float x = e.getXIndex();

	float barWidth = 0.5f;

	float spaceHalf = barspace / 2f;
	float left = x - barWidth + spaceHalf;
	float right = x + barWidth - spaceHalf;
	float top = y >= 0 ? y : 0;
	float bottom = y <= 0 ? y : 0;

	RectF bounds = new RectF(left, top, right, bottom);

	getTransformer(set.getAxisDependency()).rectValueToPixel(bounds);

	return bounds;
}
 
Example 17
Project: P2P   File: BarHighlighter.java   View source code 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

	Highlight h = super.getHighlight(x, y);

	if (h == null)
		return h;
	else {

		BarDataSet set = mChart.getBarData().getDataSetByIndex(h.getDataSetIndex());

		if (set.isStacked()) {

			// create an array of the touch-point
			float[] pts = new float[2];
			pts[1] = y;

			// take any transformer to determine the x-axis value
			mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts);

			return getStackedHighlight(h, set, h.getXIndex(), h.getDataSetIndex(), pts[1]);
		} else
			return h;
	}
}
 
Example 18
Project: P2P   File: HorizontalBarHighlighter.java   View source code 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

	Highlight h = super.getHighlight(x, y);

	if (h == null)
		return h;
	else {

		BarDataSet set = mChart.getBarData().getDataSetByIndex(h.getDataSetIndex());

		if (set.isStacked()) {

			// create an array of the touch-point
			float[] pts = new float[2];
			pts[0] = y;

			// take any transformer to determine the x-axis value
			mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts);

			return getStackedHighlight(h, set, h.getXIndex(), h.getDataSetIndex(), pts[0]);
		} else
			return h;
	}
}
 
Example 19
Project: P2P   File: BarChartActivity.java   View source code 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 20
Project: react-native-mp-android-chart   File: BarChartManager.java   View source code 6 votes vote down vote up
@Override
void dataSetConfig(IDataSet<BarEntry> dataSet, ReadableMap config) {
    BarDataSet barDataSet = (BarDataSet) dataSet;

    ChartDataSetConfigUtils.commonConfig(barDataSet, config);
    ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(barDataSet, config);

    if (BridgeUtils.validate(config, ReadableType.Number, "barSpacePercent")) {
        barDataSet.setBarSpacePercent((float) config.getDouble("barSpacePercent"));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "barShadowColor")) {
        barDataSet.setBarShadowColor(Color.parseColor(config.getString("barShadowColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.Number, "highlightAlpha")) {
        barDataSet.setHighLightAlpha(config.getInt("highlightAlpha"));
    }
    if (BridgeUtils.validate(config, ReadableType.Array, "stackLabels")) {
        barDataSet.setStackLabels(BridgeUtils.convertToStringArray(config.getArray("stackLabels")));
    }
}
 
Example 21
Project: Sxumiro_AndroidClient   File: ListViewMultiChartFragment.java   View source code 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 22
Project: xs-android-architecture   File: SimpleFragment.java   View source code 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(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 23
Project: xs-android-architecture   File: ListViewBarChartActivity.java   View source code 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(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<IBarDataSet>();
    sets.add(d);
    
    BarData cd = new BarData(sets);
    cd.setBarWidth(0.9f);
    return cd;
}
 
Example 24
Project: xs-android-architecture   File: ListViewMultiChartActivity.java   View source code 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(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 25
Project: xs-android-architecture   File: ScrollViewActivity.java   View source code 6 votes vote down vote up
private void setData(int count) {
    
    ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();

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

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

    BarData data = new BarData(set);

    mChart.setData(data);
    mChart.invalidate();
    mChart.animateY(800);
}
 
Example 26
Project: GoldenQuranAndroid   File: StatisticsFragment.java   View source code 6 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);

        BarDataSet barDataSet1 = new BarDataSet(valueSet1, "Reading Status");
        barDataSet1.setColor(Color.rgb(255, 127, 80));

        dataSets = new ArrayList<>();
        dataSets.add(barDataSet1);
        return dataSets;
    }
 
Example 27
Project: FaceT   File: ProductDetailActivity.java   View source code 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 28
Project: 2016.2-CidadeDemocratica   File: CharterGenerator.java   View source code 6 votes vote down vote up
private static void setData(Chart barChart, List<Pair<String, Integer>> chartData, String title, Context context) {

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

        int count = chartData.size() > 10 ? 10 : chartData.size();
        for (int i = 0; i < count; i++) { //10 top states
            yVals.add(new BarEntry(i,chartData.get(i).second));
        }

        BarDataSet barDataSet = new BarDataSet(yVals, title);

        int[] colors = new int[]{context.getResources().getColor(R.color.colorChart1),
                context.getResources().getColor(R.color.colorChart2),
                context.getResources().getColor(R.color.colorChart3),
                context.getResources().getColor(R.color.colorChart4),
                context.getResources().getColor(R.color.colorChart5)};

        barDataSet.setColors(colors);

        BarData data = new BarData(barDataSet);
        data.setValueTextSize(12f);

        barChart.setData(data);
    }
 
Example 29
Project: gadgetbridge_artikcloud   File: AbstractChartFragment.java   View source code 6 votes vote down vote up
protected BarDataSet createActivitySet(List<BarEntry> values, List<Integer> colors, String label) {
        BarDataSet set1 = new BarDataSet(values, label);
        set1.setColors(colors);
//        set1.setDrawCubic(true);
//        set1.setCubicIntensity(0.2f);
//        //set1.setDrawFilled(true);
//        set1.setDrawCircles(false);
//        set1.setLineWidth(2f);
//        set1.setCircleSize(5f);
//        set1.setFillColor(ColorTemplate.getHoloBlue());
        set1.setDrawValues(false);
//        set1.setHighLightColor(Color.rgb(128, 0, 255));
//        set1.setColor(Color.rgb(89, 178, 44));
        set1.setValueTextColor(CHART_TEXT_COLOR);
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);
        return set1;
    }
 
Example 30
Project: gadgetbridge_artikcloud   File: AbstractChartFragment.java   View source code 6 votes vote down vote up
protected BarDataSet createLightSleepSet(List<BarEntry> values, String label) {
        BarDataSet set1 = new BarDataSet(values, label);

//        set1.setDrawCubic(true);
//        set1.setCubicIntensity(0.2f);
//        //set1.setDrawFilled(true);
//        set1.setDrawCircles(false);
//        set1.setLineWidth(2f);
//        set1.setCircleSize(5f);
//        set1.setFillColor(ColorTemplate.getHoloBlue());
        set1.setDrawValues(false);
//        set1.setHighLightColor(Color.rgb(244, 117, 117));
//        set1.setColor(Color.rgb(182, 191, 255));
        set1.setValueTextColor(CHART_TEXT_COLOR);
//        set1.setColor(Color.CYAN);
        return set1;
    }
 
Example 31
Project: bounswe2016group2   File: userHomeFragment.java   View source code 6 votes vote down vote up
/**
     * Generate bar data bar data.
     *
     * @param dataSets the data sets
     * @param range    the range
     * @param count    the count
     * @return the bar data
     */
    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(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 32
Project: beaconradar   File: DetailsActivity.java   View source code 6 votes vote down vote up
/**
 * Procedure to add last DetailsData sample to chart.
 * @param data
 * @param chart
 */
private void insertChartSample(DetailsData data, BarChart chart, @Nullable Beacon beacon) {
    data.insertAndUpdate(beacon);
    BarData barData = chart.getData();
    BarDataSet set = barData.getDataSetByIndex(0);
    if(set.getEntryCount() == mPresenter.getSamplesCount()) {
        barData.removeXValue(0);
        set.removeEntry(0);
        for (Entry entry : set.getYVals()) {
            entry.setXIndex(entry.getXIndex() - 1);
        }
    }
    barData.addXValue(" ");
    BarEntry newEntry = new BarEntry(
            data.getCurrentValue(mPresenter.getMode()),
            set.getEntryCount());
    barData.addEntry(newEntry, 0);
    setChartRange(chart, data, mPresenter.getAutoscale());
    setChartAverage(chart, data, mPresenter.getAverage());

    chart.notifyDataSetChanged();
    chart.invalidate();
}
 
Example 33
Project: AndroidDatabaseLibraryComparison   File: MainActivity.java   View source code 6 votes vote down vote up
private void initChart() {
    ArrayList<BarDataSet> dataSets = new ArrayList<>();
    // note that we show save first because that's how we initialize the DB
    for (String frameworkName : chartEntrySets.keySet()) {
        ArrayList<BarEntry> entrySet = chartEntrySets.get(frameworkName);
        BarDataSet dataSet = new BarDataSet(entrySet, frameworkName);
        dataSet.setColor(getFrameworkColor(frameworkName));
        dataSets.add(dataSet);
    }
    // load data and animate it
    ArrayList<String> xAxisLabels = new ArrayList<>();
    xAxisLabels.add("Save (msec)");
    xAxisLabels.add("Load (msec)");
    BarData data = new BarData(xAxisLabels, dataSets);
    chartView.setData(data);
    chartView.setDescription(null); // this takes up too much space, so clear it
    chartView.animateXY(2000, 2000);
    chartView.invalidate();
}
 
Example 34
Project: mobile-manager-for-cloudflare   File: BarChart.java   View source code 6 votes vote down vote up
/**
 * Returns the bounding box of the specified Entry in the specified DataSet.
 * Returns null if the Entry could not be found in the charts data.
 * 
 * @param e
 * @param dataSetIndex
 * @return
 */
public RectF getBarBounds(BarEntry e) {

    BarDataSet set = mData.getDataSetForEntry(e);

    if (set == null)
        return null;

    float barspace = set.getBarSpace();
    float y = e.getVal();
    float x = e.getXIndex();

    float spaceHalf = barspace / 2f;
    float left = x + spaceHalf;
    float right = x + 1f - spaceHalf;
    float top = y >= 0 ? y : 0;
    float bottom = y <= 0 ? y : 0;

    RectF bounds = new RectF(left, top, right, bottom);

    mTrans.rectValueToPixel(bounds);

    return bounds;
}
 
Example 35
Project: mobile-manager-for-cloudflare   File: BarLineChartBase.java   View source code 6 votes vote down vote up
/**
 * Returns the position (in pixels) the provided Entry has inside the chart
 * view or null, if the provided Entry is null.
 * 
 * @param e
 * @return
 */
public PointF getPosition(Entry e) {

    if (e == null)
        return null;

    float[] vals = new float[] {
            e.getXIndex(), e.getVal()
    };

    if (this instanceof BarChart) {

        BarDataSet set = (BarDataSet) mData.getDataSetForEntry(e);
        if (set != null)
            vals[0] += set.getBarSpace() / 2f;
    }

    mTrans.pointValuesToPixel(vals);

    return new PointF(vals[0], vals[1]);
}
 
Example 36
Project: eCarNet   File: BarChartCustom.java   View source code 6 votes vote down vote up
public BarChartCustom(BarChart graphical, ArrayList<BarEntry> entries, String entriesLegend, ArrayList<String> labels, String chartDecription)
{
    this.entries = entries;
    this.chart = graphical;
    this.dataset = new BarDataSet(entries, entriesLegend);
    this.data = new BarData(labels, this.dataset);
    this.colors = new ArrayList<>();
    this.yLeftAxis = chart.getAxisLeft();
    this.yRightAxis = chart.getAxisRight();
    this.xAxis = chart.getXAxis();
    chart.setTouchEnabled(false);
    this.average = new LimitLine(getAverage(), String.format("%1$s : %2$.2f", "Moyenne", getAverage()));
    this.average.setTextSize(10);
    this.average.setLineColor(Color.RED);
    this.average.setLineWidth(1.5f);
    this.yLeftAxis.addLimitLine(average);
    this.average.setEnabled(false);
    this.legend = chart.getLegend();
    if(chartDecription!= null)
        chart.setDescription(chartDecription);
    else chart.setDescription("");
    setDefaultChart();
    setDefaultLegend();
    setDefaultAxes();
}
 
Example 37
Project: NoiseCapture   File: MeasurementActivity.java   View source code 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 38
Project: Expense-Tracker-App   File: StatisticsFragment.java   View source code 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 39
Project: MPAndroidChart   File: SimpleFragment.java   View source code 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(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 40
Project: MPAndroidChart   File: ListViewBarChartActivity.java   View source code 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(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<IBarDataSet>();
    sets.add(d);
    
    BarData cd = new BarData(sets);
    cd.setBarWidth(0.9f);
    return cd;
}