Java Code Examples for com.github.mikephil.charting.charts.PieChart#setData()

The following examples show how to use com.github.mikephil.charting.charts.PieChart#setData() . 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: PieChartFrag.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_pie, container, false);
    
    mChart = (PieChart) v.findViewById(R.id.pieChart1);
    mChart.setDescription("");
    
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
    
    mChart.setCenterTextTypeface(tf);
    mChart.setCenterText(generateCenterText());
    mChart.setCenterTextSize(10f);
    mChart.setCenterTextTypeface(tf);
     
    // radius of the center hole in percent of maximum radius
    mChart.setHoleRadius(45f);
    mChart.setTransparentCircleRadius(50f);
    
    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    
    mChart.setData(generatePieData());
    
    return v;
}
 
Example 2
Source File: ProductDetailActivity.java    From FaceT with 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 3
Source File: ReportAdapter.java    From outlay with 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 4
Source File: StatisticsLogic.java    From BrainPhaser with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a PieData object containing entries with the numbers of due and not due challenges.
 *
 * @param chart the PieChart object the calculated data will be applied to
 * @param type  the type of the statistic to be created
 * @return a list of the ids of the shown challenges, if a most played / failed / succeeded
 * challenges chart is created. Otherwise null will be returned.
 */
public List<Long> fillChart(PieChart chart, StatisticType type) {
    if (chart == null) return null;

    //Clear the chart for reloading
    chart.clear();

    //Create chart data
    List<Long> shownChallenges = new ArrayList<>();
    PieData data;

    //Find chart data and apply type specific settings
    switch (type) {
        case TYPE_DUE:
            data = mDataLogic.findDueData();
            chart.setCenterText(mApplication.getString(R.string.due_chart_center_text));
            break;
        case TYPE_STAGE:
            data = mDataLogic.findStageData();
            chart.setCenterText(mApplication.getString(R.string.stage_chart_center_text));
            break;
        default:
            data = mDataLogic.findMostPlayedData(type, shownChallenges);
            chart.setCenterText("");
            chart.getLegend().setEnabled(false);
    }

    if (data != null) {
        //Add data to chart
        chart.setData(data);

        //Apply default chart settings to the chart
        mSettings.applyChartSettings(chart);
    } else {
        //Format the no data text of the chart
        mSettings.applyNoDataSettings(chart);
    }

    //If there are shown challenges in the List object return the List object, else return null
    return (shownChallenges.size() > 0) ? shownChallenges : null;
}
 
Example 5
Source File: ColorDetectionActivity.java    From FaceT with Mozilla Public License 2.0 4 votes vote down vote up
private void setData(PieChart colorPie, int order, int color) {

        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
        float colorValue = color / 255f;
        entries.add(new PieEntry(colorValue, 0));
        entries.add(new PieEntry(1 - colorValue, 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);
        colorPie.setCenterTextColor(ColorTemplate.getHoloBlue());

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

        // add a lot of colors
        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.clear();
        switch (order) {
            case 0:
                colors.add(Color.argb(100, color, 0, 0));
                colorPie.setCenterText("Red");
                break;
            case 1:
                colors.add(Color.argb(100, 0, color, 0));
                colorPie.setCenterText("Green");
                break;
            case 2:
                colors.add(Color.argb(100, 0, 0, color));
                colorPie.setCenterText("Blue");
                break;
        }
        colors.add(Color.argb(80, 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();
    }