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

The following examples show how to use com.github.mikephil.charting.charts.PieChart#highlightValues() . 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: 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 2
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 3
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();
    }