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

The following examples show how to use com.github.mikephil.charting.data.PieData. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: SEAL-Demo   Source File: PredictionsFragment.java    License: MIT License 6 votes vote down vote up
/**
 * Updates the data in the pie chart with all the runs.
 */
private void updatePieChart() {
    ArrayList<PieEntry> entries = filterPieEntries();
    PieDataSet dataSet = new PieDataSet(entries, "Predictions");
    dataSet.setDrawIcons(false);
    dataSet.setSliceSpace(2f);
    dataSet.setIconsOffset(new MPPointF(0, 40));
    dataSet.setSelectionShift(5f);
    dataSet.setColors(new int[]{R.color.classification_low_intensity, R.color.classification_medium_intensity, R.color.classification_high_intensity}, getActivity());
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(22f);
    data.setValueTextColor(Color.WHITE);
    mChart.setData(data);
    mChart.invalidate();
}
 
Example 2
private void updateChart(String totalSpace, List<PieEntry> entries) {
    boolean isDarkTheme = appTheme.getMaterialDialogTheme() == Theme.DARK;

    PieDataSet set = new PieDataSet(entries, null);
    set.setColors(COLORS);
    set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    set.setSliceSpace(5f);
    set.setAutomaticallyDisableSliceSpacing(true);
    set.setValueLinePart2Length(1.05f);
    set.setSelectionShift(0f);

    PieData pieData = new PieData(set);
    pieData.setValueFormatter(new GeneralDialogCreation.SizeFormatter(context));
    pieData.setValueTextColor(isDarkTheme? Color.WHITE:Color.BLACK);

    chart.setCenterText(new SpannableString(context.getString(R.string.total) + "\n" + totalSpace));
    chart.setData(pieData);
}
 
Example 3
Source Project: StockChart-MPAndroidChart   Source File: SimpleFragment.java    License: MIT License 6 votes vote down vote up
/**
 * generates less data (1 DataSet, 4 values)
 * @return PieData
 */
protected PieData generatePieData() {

    int count = 4;

    ArrayList<PieEntry> entries1 = new ArrayList<>();

    for(int i = 0; i < count; i++) {
        entries1.add(new PieEntry((float) ((Math.random() * 60) + 40), "Quarter " + (i+1)));
    }

    PieDataSet ds1 = new PieDataSet(entries1, "Quarterly Revenues 2015");
    ds1.setColors(ColorTemplate.VORDIPLOM_COLORS);
    ds1.setSliceSpace(2f);
    ds1.setValueTextColor(Color.WHITE);
    ds1.setValueTextSize(12f);

    PieData d = new PieData(ds1);
    d.setValueTypeface(tf);

    return d;
}
 
Example 4
Source Project: StockChart-MPAndroidChart   Source File: HalfPieChartActivity.java    License: MIT License 6 votes vote down vote up
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            values.add(new PieEntry((float) ((Math.random() * range) + range / 5), parties[i % parties.length]));
        }

        PieDataSet dataSet = new PieDataSet(values, "Election Results");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);

        dataSet.setColors(ColorTemplate.MATERIAL_COLORS);
        //dataSet.setSelectionShift(0f);

        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.WHITE);
        data.setValueTypeface(tfLight);
        chart.setData(data);

        chart.invalidate();
    }
 
Example 5
/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Pie data
 */
private PieData generateDataPie() {

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

    for (int i = 0; i < 4; i++) {
        entries.add(new PieEntry((float) ((Math.random() * 70) + 30), "Quarter " + (i+1)));
    }

    PieDataSet d = new PieDataSet(entries, "");

    // space between slices
    d.setSliceSpace(2f);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);

    return new PieData(d);
}
 
Example 6
Source Project: iMoney   Source File: PieChartActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 */
private PieData generateDataPie() {

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

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

    PieDataSet d = new PieDataSet(entries, "");

    // 设置各个扇形部分之间的间距
    d.setSliceSpace(12f);
    // 设置各个扇形部分的颜色
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);

    PieData cd = new PieData(getQuarters(), d);
    return cd;
}
 
Example 7
Source Project: Stayfit   Source File: ListViewMultiChartActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private PieData generateDataPie(int cnt) {

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

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

    PieDataSet d = new PieDataSet(entries, "");
    
    // space between slices
    d.setSliceSpace(2f);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    
    PieData cd = new PieData(getQuarters(), d);
    return cd;
}
 
Example 8
Source Project: ResearchStack   Source File: PieChartCard.java    License: Apache License 2.0 6 votes vote down vote up
public void setData(PieData data) {
    chart.setData(data);
    chart.notifyDataSetChanged();
    chart.invalidate();

    rowContainer.removeAllViews();
    LayoutInflater inflater = LayoutInflater.from(getContext());

    for (int i = 0, size = data.getXVals().size(); i < size; i++) {
        String xVal = data.getXVals().get(i);
        float entryValue = data.getDataSet().getEntryForIndex(i).getVal();

        View row = inflater.inflate(R.layout.rsb_item_chart_pie, rowContainer, false);

        TextView label = (TextView) row.findViewById(R.id.item_chart_pie_label);
        label.setText(xVal);
        label.setTextColor(data.getDataSet().getColor(i));

        TextView value = (TextView) row.findViewById(R.id.item_chart_pie_value);
        value.setText(getContext().getString(valueTextFormat, numberFormat.format(entryValue)));
        value.setTextColor(data.getDataSet().getColor(i));

        rowContainer.addView(row);
    }
}
 
Example 9
Source Project: Mi-Band   Source File: SleepChartActivity.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void refreshSleepAmounts(List<ActivityData> samples) {
    ActivityAnalysis analysis = new ActivityAnalysis();
    ActivityAmounts amounts = analysis.calculateActivityAmounts(samples);
    float hoursOfSleep = amounts.getTotalSeconds() / (float) (60 * 60);
    pieChart.setCenterText((int) hoursOfSleep + "h"); // FIXME
    PieData data = new PieData();
    List<Entry> entries = new ArrayList<>();
    List<Integer> colors = new ArrayList<>();
    int index = 0;
    for (ActivityAmount amount : amounts.getAmounts()) {
        entries.add(new Entry(amount.getTotalSeconds(), index++));
        colors.add(getColorFor(amount.getActivityKind()));
        data.addXValue(amount.getName());
    }
    PieDataSet set = new PieDataSet(entries, "Sleep comparison");
    set.setColors(colors);
    data.setDataSet(set);
    pieChart.setData(data);

    //setupLegend(pieChart);

    pieChart.invalidate();
}
 
Example 10
Source Project: dbclf   Source File: CameraActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setupPieChart() {
    mChart.getDescription().setEnabled(false);
    mChart.setUsePercentValues(true);
    mChart.setTouchEnabled(false);

    // show center text only first time
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    final boolean previouslyStarted = prefs.getBoolean("showhelp", false);
    if (!previouslyStarted) {
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean("showhelp", Boolean.TRUE);
        edit.apply();

        mChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"));
        mChart.setCenterText(generateCenterSpannableText());
        mChart.setCenterTextSizePixels(23);
        mChart.setDrawCenterText(true);
    }

    mChart.setExtraOffsets(14, 0.f, 14, 0.f);
    mChart.setHoleRadius(85);
    mChart.setHoleColor(Color.TRANSPARENT);
    mChart.setHovered(true);
    mChart.setDrawMarkers(false);
    mChart.setRotationEnabled(false);
    mChart.setHighlightPerTapEnabled(false);
    mChart.getLegend().setEnabled(false);
    mChart.setAlpha(0.9f);

    // display unknown slice
    final ArrayList<PieEntry> entries = new ArrayList<>();
    // set unknown slice to transparent
    entries.add(new PieEntry(100, ""));
    final PieDataSet set = new PieDataSet(entries, "");
    set.setColor(R.color.transparent);
    set.setDrawValues(false);

    final PieData data = new PieData(set);
    mChart.setData(data);
}
 
Example 11
Source Project: StockChart-MPAndroidChart   Source File: PieChartRenderer.java    License: MIT License 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    Bitmap drawBitmap = mDrawBitmap == null ? null : mDrawBitmap.get();

    if (drawBitmap == null
            || (drawBitmap.getWidth() != width)
            || (drawBitmap.getHeight() != height)) {

        if (width > 0 && height > 0) {
            drawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
            mDrawBitmap = new WeakReference<>(drawBitmap);
            mBitmapCanvas = new Canvas(drawBitmap);
        } else {
            return;
        }
    }

    drawBitmap.eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0) {
            drawDataSet(c, set);
        }
    }
}
 
Example 12
Source Project: android-ponewheel   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
public void updateBatteryRemaining(final int percent) {
    // Update ongoing notification
    notify.remain(percent);
    notify.alert(percent);

    runOnUiThread(() -> {
        try {
            ArrayList<PieEntry> entries = new ArrayList<>();
            entries.add(new PieEntry(percent, 0));
            entries.add(new PieEntry(100 - percent, 1));
            PieDataSet dataSet = new PieDataSet(entries, "battery percentage");
            ArrayList<Integer> mColors = new ArrayList<>();
            mColors.add(ColorTemplate.rgb("#2E7D32")); //green
            mColors.add(ColorTemplate.rgb("#C62828")); //red
            dataSet.setColors(mColors);
            dataSet.setDrawValues(false);

            PieData newPieData = new PieData( dataSet);
            mBatteryChart.setCenterText(percent + "%");
            mBatteryChart.setCenterTextTypeface(Typeface.DEFAULT_BOLD);
            mBatteryChart.setCenterTextColor(ColorTemplate.rgb("#616161"));
            mBatteryChart.setCenterTextSize(20f);
            mBatteryChart.setDescription(null);

            mBatteryChart.setData(newPieData);
            mBatteryChart.notifyDataSetChanged();
            mBatteryChart.invalidate();
        } catch (Exception e) {
            Timber.e( "Got an exception updating battery:" + e.getMessage());
        }
    });

    alertsController.handleChargePercentage(percent);
}
 
Example 13
Source Project: Ticket-Analysis   Source File: PieChartRenderer.java    License: MIT License 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example 14
Source Project: android-kline   Source File: PieChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example 15
Source Project: ToDay   Source File: GraphicActivity.java    License: MIT License 5 votes vote down vote up
private void addDataSet() {
    Log.d(TAG, "addDataSet started");
    ArrayList<PieEntry> yEntrys = new ArrayList<>();
    ArrayList<String> xEntrys = new ArrayList<>();

    for(int i = 0; i < yData.length; i++){
        yEntrys.add(new PieEntry(yData[i] , i));
    }

    for(int i = 1; i < xData.length; i++){
        xEntrys.add(xData[i]);
    }

    //create the data set
    PieDataSet pieDataSet = new PieDataSet(yEntrys, "Төлөвлөгөөний үзүүлэлтлл");
    pieDataSet.setSliceSpace(2);
    pieDataSet.setValueTextSize(12);

    //add colors to dataset
    ArrayList<Integer> colors = new ArrayList<>();
    colors.add(Color.GRAY);
    colors.add(Color.BLUE);
    colors.add(Color.RED);
    colors.add(Color.GREEN);
    colors.add(Color.CYAN);
    colors.add(Color.YELLOW);
    colors.add(Color.MAGENTA);

    pieDataSet.setColors(colors);

    //add legend to chart
    Legend legend = pieChart.getLegend();
    legend.setForm(Legend.LegendForm.CIRCLE);
    legend.setPosition(Legend.LegendPosition.LEFT_OF_CHART);

    //create pie data object
    PieData pieData = new PieData(pieDataSet);
    pieChart.setData(pieData);
    pieChart.invalidate();
}
 
Example 16
Source Project: iMoney   Source File: PieChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.getWidth() != width)
            || (mDrawBitmap.getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
            mBitmapCanvas = new Canvas(mDrawBitmap);
        } else
            return;
    }

    mDrawBitmap.eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (PieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example 17
Source Project: BrainPhaser   Source File: ChartDataLogic.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a PieData object containing entries with the numbers of due and not due challenges
 *
 * @return PieData object containing the numbers of the due and not due challenges
 */
public PieData findDueData() {
    //Calculate numbers for the data to be visualized
    DueChallengeLogic dueChallengeLogic = mUserLogicFactory.createDueChallengeLogic(mUser);

    //Retrieve due numbers
    int dueNumber = dueChallengeLogic.getDueChallenges(mCategoryId).size();
    int notDueNumber = mChallengeDataSource.getByCategoryId(mCategoryId).size() - dueNumber;

    if (dueNumber + notDueNumber > 0) {
        //Create lists
        ArrayList<Entry> entries = new ArrayList<>();
        ArrayList<String> labels = new ArrayList<>();

        //Add entries
        labels.add(mApplication.getString(R.string.challenge_due_text));
        entries.add(new Entry(dueNumber > 0 ? dueNumber : nullValue(notDueNumber), 0));

        labels.add(mApplication.getString(R.string.challeng_not_due_text));
        entries.add(new Entry(notDueNumber > 0 ? notDueNumber : nullValue(dueNumber), 1));

        //Create dataset
        PieDataSet dataset = new PieDataSet(entries, "");
        mSettings.applyDataSetSettings(dataset, StatisticType.TYPE_DUE);

        //Create data
        PieData data = new PieData(labels, dataset);
        mSettings.applyDataSettings(data);

        //Return the PieData object
        return data;
    } else
        return null;
}
 
Example 18
Source Project: BrainPhaser   Source File: ChartDataLogic.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a PieData object containing entries with the numbers of challenges in each stage
 *
 * @return PieData object containing the numbers of the challenges in each stage
 */
public PieData findStageData() {
    //Create lists
    ArrayList<Entry> entries = new ArrayList<>();
    ArrayList<String> labels = new ArrayList<>();

    //Retrieve stage numbers
    int numbers[] = {0, 0, 0, 0, 0, 0};
    int totalNumber = 0;

    for (int i = 0; i <= 5; i++) {
        numbers[i] = mCompletionDataSource.findByUserAndStageAndCategory(mUser, i + 1,
                mCategoryId).size();
        totalNumber += numbers[i];
    }
    if (totalNumber > 0) {
        //Add entries
        for (int i = 0; i <= 5; i++) {
            entries.add(new Entry(numbers[i] != 0 ? numbers[i] : nullValue(totalNumber), i));
            labels.add("" + (i + 1));
        }
        //Create dataset
        PieDataSet dataset = new PieDataSet(entries, "");
        mSettings.applyDataSetSettings(dataset, StatisticType.TYPE_STAGE);

        //Create data
        PieData data = new PieData(labels, dataset);
        mSettings.applyDataSettings(data);

        //Return the PieData object
        return data;
    } else
        return null;
}
 
Example 19
Source Project: Stayfit   Source File: PieChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example 20
Source Project: Stayfit   Source File: SimpleFragment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * generates less data (1 DataSet, 4 values)
 * @return
 */
protected PieData generatePieData() {
    
    int count = 4;
    
    ArrayList<Entry> entries1 = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    
    xVals.add("Quarter 1");
    xVals.add("Quarter 2");
    xVals.add("Quarter 3");
    xVals.add("Quarter 4");
    
    for(int i = 0; i < count; i++) {
        xVals.add("entry" + (i+1));

        entries1.add(new Entry((float) (Math.random() * 60) + 40, i));
    }
    
    PieDataSet ds1 = new PieDataSet(entries1, "Quarterly Revenues 2015");
    ds1.setColors(ColorTemplate.VORDIPLOM_COLORS);
    ds1.setSliceSpace(2f);
    ds1.setValueTextColor(Color.WHITE);
    ds1.setValueTextSize(12f);
    
    PieData d = new PieData(xVals, ds1);
    d.setValueTypeface(tf);

    return d;
}
 
Example 21
Source Project: NetKnight   Source File: PieChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example 22
private void setData(long tips, long transactionsToRequest) {

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

        entries.add(new PieEntry(tips, getString(R.string.tips) + " " + "(" + tips + ")"));
        entries.add(new PieEntry(transactionsToRequest, getString(R.string.transactions_to_request) + " " + "(" + transactionsToRequest + ")"));

        PieDataSet dataSet = new PieDataSet(entries, getString(R.string.transactions) + "\n(" + (tips + transactionsToRequest) + ")");

        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);

        // add a lot of colors

        ArrayList<Integer> colors = new ArrayList<>();

        for (int c : ColorTemplate.LIBERTY_COLORS)
            colors.add(c);

        dataSet.setColors(colors);

        dataSet.setValueLinePart1OffsetPercentage(80.f);
        dataSet.setValueLinePart1Length(0.2f);
        dataSet.setValueLinePart2Length(0.4f);
        dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
        dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
        dataSet.setValueTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));

        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(12f);
        data.setValueTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
        chart.setData(data);

        // undo all highlights
        chart.highlightValues(null);
        chart.invalidate();
    }
 
Example 23
Source Project: FaceT   Source File: ProductDetailActivity.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private void setData(PieChart colorPie, float value) {

        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
        float result = value / 5f;
        Log.d(TAG + " result ", result + "");
        entries.add(new PieEntry(result, 0));
        entries.add(new PieEntry(1 - result, 1));
        // NOTE: The order of the entries when being added to the entries array determines their position around the center of
        // the chart.

//        colorPie.setCenterTextTypeface(mTfLight);
        int centerTextColor = android.graphics.Color.argb(255, 57, 197, 193);
        colorPie.setCenterTextColor(centerTextColor);

        PieDataSet dataSet = new PieDataSet(entries, "");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(3f);

        // add a lot of colors
        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.add(Color.argb(120, 57, 197, 193));
        colorPie.setCenterText(value + "");
        colorPie.setCenterTextSize(30);

        colors.add(Color.argb(100, 214, 214, 214));
        dataSet.setColors(colors);

        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(0f);
        data.setValueTextColor(Color.WHITE);
        colorPie.setData(data);

        // undo all highlights
        colorPie.highlightValues(null);

        colorPie.invalidate();
    }
 
Example 24
Source Project: outlay   Source File: ReportAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void updateChartData(PieChart chart) {
    ArrayList<PieEntry> entries = new ArrayList<>();
    ArrayList<Integer> colors = new ArrayList<>();

    double sum = 0;
    for (int i = 0; i < categorizedExpenses.getCategories().size(); i++) {
        Category c = categorizedExpenses.getCategory(i);
        Report r = categorizedExpenses.getReport(c);
        sum += r.getTotalAmount().doubleValue();
        entries.add(new PieEntry((int) (r.getTotalAmount().doubleValue() * 1000), c.getTitle()));
        colors.add(c.getColor());
    }

    PieDataSet dataSet = new PieDataSet(entries, "Outlay");
    dataSet.setSliceSpace(2f);
    dataSet.setSelectionShift(10f);
    dataSet.setColors(colors);

    PieData data = new PieData(dataSet);
    data.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> NumberUtils.formatAmount((double) value / 1000));
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.WHITE);
    chart.setData(data);
    chart.setCenterText(NumberUtils.formatAmount(sum));
    chart.highlightValues(null);
    chart.invalidate();
}
 
Example 25
Source Project: NoiseCapture   Source File: Results.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void setRNEData(List<Double> classRangeValue) {
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();

    // IMPORTANT: In a PieChart, no values (Entry) should have the same
    // xIndex (even if from different DataSets), since no values can be
    // drawn above each other.
    catNE= getResources().getStringArray(R.array.catNE_list_array);
    ArrayList<String> xVals = new ArrayList<String>();
    double maxValue = 0;
    int maxClassId = 0;
    for (int idEntry = 0; idEntry < classRangeValue.size(); idEntry++) {
        float value = classRangeValue.get(classRangeValue.size() - 1 - idEntry).floatValue();
        // Fix background color issue if the pie is too thin
        if(value < 0.01) {
            value = 0;
        }
        yVals1.add(new Entry(value, idEntry));
        xVals.add(catNE[idEntry]);
        if (value > maxValue) {
            maxClassId = idEntry;
            maxValue = value;
        }
    }

    PieDataSet dataSet = new PieDataSet(yVals1,Results.this.getString(R.string.caption_SL));
    dataSet.setSliceSpace(3f);
    dataSet.setColors(NE_COLORS);

    PieData data = new PieData(xVals, dataSet);
    data.setValueFormatter(new CustomPercentFormatter());
    data.setValueTextSize(8f);
    data.setValueTextColor(Color.BLACK);
    rneChart.setData(data);

    // highlight the maximum value of the RNE
    // Find the maximum of the array, in order to be highlighted
    Highlight h = new Highlight(maxClassId, 0);
    rneChart.highlightValues(new Highlight[] { h });
    rneChart.invalidate();
}
 
Example 26
Source Project: NoiseCapture   Source File: Results.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void setNEIData() {

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

        // IMPORTANT: In a PieChart, no values (Entry) should have the same
        // xIndex (even if from different DataSets), since no values can be
        // drawn above each other.
        yVals1.add(new Entry( record.getLeqMean(), 0));

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

        xVals.add(catNE[0 % catNE.length]);

        PieDataSet dataSet = new PieDataSet(yVals1, "NEI");
        dataSet.setSliceSpace(3f);
        int nc=getNEcatColors(record.getLeqMean());    // Choose the color category in function of the sound level
        dataSet.setColor(NE_COLORS[nc]);   // Apply color category for the corresponding sound level

        PieData data = new PieData(xVals, dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.BLACK);
        data.setDrawValues(false);

        neiChart.setData(data);
        neiChart.setCenterText(String.format(Locale.getDefault(), "%.1f", record.getLeqMean())
                .concat(" dB(A)" + ""));
        neiChart.invalidate();
    }
 
Example 27
Source Project: Expense-Tracker-App   Source File: StatisticsFragment.java    License: MIT License 5 votes vote down vote up
private void setCategoriesPieChart() {

        List<String> categoriesNames = new ArrayList<>();
        List<Entry> categoryPercentagesEntries = new ArrayList<>();

        for (int i=0; i < mCategoryList.size(); i++) {
            float percentage = Expense.getExpensesCategoryPercentage(DateManager.getInstance().getDateFrom(), DateManager.getInstance().getDateTo(), mCategoryList.get(i));
            if( percentage > 0) {
                categoriesNames.add(mCategoryList.get(i).getName());
                Entry pieEntry = new Entry(percentage, categoriesNames.size()-1);
                categoryPercentagesEntries.add(pieEntry);
            }
        }
        if (categoriesNames.isEmpty()) {
            tvPcCategoriesEmpty.setVisibility(View.VISIBLE);
            bcCategories.setVisibility(View.GONE);
        } else {
            tvPcCategoriesEmpty.setVisibility(View.GONE);
            bcCategories.setVisibility(View.VISIBLE);
        }

        PieDataSet dataSet = new PieDataSet(categoryPercentagesEntries, "Categories");
        dataSet.setSliceSpace(1f);
        dataSet.setSelectionShift(5f);

        dataSet.setColors(Util.getListColors());

        PieData data = new PieData(categoriesNames, dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(getResources().getColor(R.color.primary_dark));
        pcCategories.setData(data);
        pcCategories.invalidate();

    }
 
Example 28
Source Project: memorize   Source File: StatisticActivity.java    License: MIT License 4 votes vote down vote up
@Override
public void setStatData(int total, int memorized, int favorited, int active) {

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

    entries.add(new PieEntry((float) memorized,
            "Цээжилсэн үг " + memorized,
            getResources().getDrawable(R.drawable.ic_timeline)));
    entries.add(new PieEntry((float) favorited,
            "Цээжилж байгаа " + favorited,
            getResources().getDrawable(R.drawable.ic_timeline)));
    entries.add(new PieEntry((float) active,
            "Цээжлээгүй " + active,
            getResources().getDrawable(R.drawable.ic_timeline)));

    PieDataSet dataSet = new PieDataSet(entries, "Memorize results");

    dataSet.setDrawIcons(false);

    dataSet.setSliceSpace(3f);
    dataSet.setIconsOffset(new MPPointF(0, 40));
    dataSet.setSelectionShift(5f);

    // add a lot of colors

    ArrayList<Integer> colors = new ArrayList<Integer>();

    colors.add(getResources().getColor(R.color.chartGreen));
    colors.add(getResources().getColor(R.color.chartBlue));
    colors.add(getResources().getColor(R.color.chartPink));
    dataSet.setColors(colors);
    //dataSet.setSelectionShift(0f);

    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.WHITE);

    SpannableString s = new SpannableString("Нийт үг :" + total);
    s.setSpan(new RelativeSizeSpan(1.7f), 0, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 0, s.length(), 0);


    pieData = new PieData(dataSet);
}
 
Example 29
Source Project: memorize   Source File: StatisticActivity.java    License: MIT License 4 votes vote down vote up
public PieData getPieData() {
    return pieData;
}
 
Example 30
Source Project: memorize   Source File: PieChartItem.java    License: MIT License 4 votes vote down vote up
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, Context c) {

    ViewHolder holder;

    if (convertView == null) {

        holder = new ViewHolder();

        convertView = LayoutInflater.from(c).inflate(
                R.layout.stats_item_piechart, null);
        holder.chart = convertView.findViewById(R.id.chart);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    holder.chart.getDescription().setEnabled(false);
    holder.chart.setHoleRadius(52f);
    holder.chart.setTransparentCircleRadius(57f);
    holder.chart.setCenterText(mCenterText);
    holder.chart.setCenterTextSize(9f);
    holder.chart.setUsePercentValues(true);
    holder.chart.setExtraOffsets(5, 10, 50, 10);

    mChartData.setValueFormatter(new PercentFormatter());
    mChartData.setValueTextSize(11f);
    mChartData.setValueTextColor(Color.WHITE);
    // set data
    holder.chart.setData((PieData) mChartData);

    Legend l = holder.chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);

    holder.chart.animateY(900);

    return convertView;
}