Java 类com.github.mikephil.charting.data.PieEntry 实例源码

项目:GitHub    文件:SimpleFragment.java   
/**
 * generates less data (1 DataSet, 4 values)
 * @return
 */
protected PieData generatePieData() {

    int count = 4;

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

    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;
}
项目:GitHub    文件:HalfPieChartActivity.java   
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.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(mTfLight);
        mChart.setData(data);

        mChart.invalidate();
    }
项目:GitHub    文件:ListViewMultiChartActivity.java   
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private PieData generateDataPie(int cnt) {

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

    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);

    PieData cd = new PieData(d);
    return cd;
}
项目:CodeWatch    文件:ChartFragment.java   
private PieData generatePieData(List<PieChartItem> pieChartItems) {

        ArrayList<PieEntry> entries = new ArrayList<>();
        for (PieChartItem item : pieChartItems) {
            entries.add(new PieEntry(item.getTime(), item.getName(), item.getPercent()));
        }

        PieDataSet pieDataSet = new PieDataSet(entries, "");
        pieDataSet.setAutomaticallyDisableSliceSpacing(true);
        pieDataSet.setColors(chartColors);

        PieData pieData = new PieData(pieDataSet);
        pieData.setValueFormatter(new CustomPercentFormatter());
        pieData.setValueTextColor(Color.WHITE);
        return pieData;
    }
项目:DOUSalaries    文件:DataBaseHelper.java   
private ChartItem buildCityChartItem(SQLiteDatabase db, long period) {
    ChartItem result = null;
    Cursor cursor = buildCursorForCharts(DemographicsType.CITY, db, period);
    if (cursor != null) {
        List<PieEntry> entries = new ArrayList<>();
        while (cursor.moveToNext()) {
            if (cursor.getInt(1) > Config.SALARIES_IN_CITY) {
                entries.add(new PieEntry( cursor.getInt(1), cursor.getString(0)));
            }
        }
        if (!entries.isEmpty()){
            PieData chartData = ChartHelper.populatePieData(entries, "");
            result = new PieChartItem(context, chartData, context.getString(R.string.pie_city));
        }
        cursor.close();
    }
    return result;
}
项目:moneytracking    文件:ShowChartActivity.java   
private void createPieChart(ArrayList<PieEntry> yEntrys, ArrayList<Integer> colors) {

        //create the data set
        PieDataSet pieDataSet = new PieDataSet(yEntrys, "");
        pieDataSet.setSliceSpace(2);
        pieDataSet.setValueTextSize(12);
        pieDataSet.setColors(colors);

        pieChart.setCenterText(start.toString() + "\n" + end.toString());
        pieChart.setCenterTextColor(Color.BLACK);
        pieChart.setCenterTextSize(20);

        pieChart.animateY(2000);
        pieChart.animateX(2000);
        pieChart.getLegend().setEnabled(true);

        Description description = new Description();
        description.setText("");
        pieChart.setDescription(description);

        //create pie data object
        PieData pieData = new PieData();
        pieData.addDataSet(pieDataSet);
        pieChart.setData(pieData);
        pieChart.invalidate();
    }
项目:Opal-Chat-AnalyticsDashboard    文件:DashboardFragment.java   
private void setPieChartData(int count, float range) {

        ArrayList<PieEntry> entries = ChartData.getPieData(count, range);
        PieDataSet dataSet = new PieDataSet(entries, "Weekly spend distribution");

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

        ArrayList<Integer> colors = new ArrayList<>();
        for (int c : ColorTemplate.LIBERTY_COLORS)
            colors.add(c);
        dataSet.setColors(colors);

        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.GRAY);
        pieChart.setData(data);
        pieChart.highlightValues(null);
        pieChart.invalidate();
    }
项目:shorl    文件:DetailActivity.java   
private void setupChart(String shortClicks, String longClicks) {
    List<PieEntry> entries = new ArrayList<>();

    Float short_actual = Float.parseFloat(shortClicks);

    Float long_actual = Float.parseFloat(longClicks);

    Float short_final_percent = (short_actual / (long_actual + short_actual)) * 100;
    Float long_final_percent = (long_actual / (long_actual + short_actual)) * 100;

    if (short_actual != Float.parseFloat("0"))
        entries.add(new PieEntry(short_final_percent, getString(R.string.short_url_clicks_pie_chart)));
    if (long_actual != Float.parseFloat("0"))
        entries.add(new PieEntry(long_final_percent, getString(R.string.long_url_click_pie_chart)));
    PieDataSet set = new PieDataSet(entries, getString(R.string.url_clikc_count_pie_chart));
    set.setColors(ColorTemplate.MATERIAL_COLORS);
    PieData data = new PieData(set);
    pieChart.setData(data);
    pieChart.invalidate(); // refresh

    if (pieChart.isEmpty()) {
        pieChart.setVisibility(View.GONE);
        errorLayout.setVisibility(View.VISIBLE);

    }
}
项目:xs-android-architecture    文件:SimpleFragment.java   
/**
 * generates less data (1 DataSet, 4 values)
 * @return
 */
protected PieData generatePieData() {

    int count = 4;

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

    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;
}
项目:xs-android-architecture    文件:HalfPieChartActivity.java   
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.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(mTfLight);
        mChart.setData(data);

        mChart.invalidate();
    }
项目:xs-android-architecture    文件:ListViewMultiChartActivity.java   
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private PieData generateDataPie(int cnt) {

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

    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);

    PieData cd = new PieData(d);
    return cd;
}
项目:RecipeFinderJavaVersion    文件:DiagramUtils.java   
public PieDataSet createPieDataSet(List<PieEntry> pieEntryList,
                                   @Nullable String label,
                                   @Nullable List<Integer> colors) {
    PieDataSet pieDataSet = new PieDataSet(pieEntryList, label);
    pieDataSet.setSliceSpace(1.5f);
    pieDataSet.setSelectionShift(2f);

    pieDataSet.setDrawValues(true);

    if (colors == null) {
        colors = new ArrayList<>(3);
        colors.add(utilsUI.getColor(R.color.colorPrimaryDark));
        colors.add(utilsUI.getColor(R.color.colorPrimary));
        colors.add(utilsUI.getColor(R.color.colorAccent));
    }

    pieDataSet.setColors(colors);
    return pieDataSet;
}
项目:RecipeFinderJavaVersion    文件:RecipeAnalysisDetailsViewModel.java   
private void showResults(NutritionAnalysisResult nutritionAnalysisResult) {
    if (nutritionAnalysisResult == null)
        return;

    calories.set(context.getString(R.string.calories, nutritionAnalysisResult.getCalories()));
    yield.set(context.getString(R.string.yields, String.valueOf(nutritionAnalysisResult.getYield())));

    List<PieEntry> pieEntries = diagramUtils.preparePieEntries(nutritionAnalysisResult.getTotalNutrients());
    chartVisibility.set(pieEntries.isEmpty() ? View.GONE : View.VISIBLE);

    if (pieEntries.isEmpty())
        return;

    PieDataSet pieDataSet = diagramUtils.createPieDataSet(pieEntries, "Nutrients", null);
    pieData = diagramUtils.createPieData(pieDataSet);

    if (onDataLoadedListener != null)
        onDataLoadedListener.onDataLoaded(pieData);
}
项目:wakatime-android-client    文件:LeaderProfileFragment.java   
@NonNull
private PieData getData(Leader leader) {
    RealmList<Language> languages = leader.getRunningTotal().getLanguages();
    List<PieEntry> entries = new ArrayList<>(languages.size());
    List<Integer> colors = new ArrayList<>(languages.size());
    for (Language language : languages) {
        entries.add(new PieEntry(language.getTotalSeconds(), language.getName()));
        colors.add(linguist.decode(language.getName()));
    }
    PieDataSet pieDataSet = new PieDataSet(entries, getString(R.string.languages));

    pieDataSet.setColors(colors);
    pieDataSet.setSliceSpace(3f);
    pieDataSet.setSelectionShift(5f);
    PieData pieData = new PieData(pieDataSet);
    pieData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> String.valueOf(toMinutes((long) value)));
    pieData.setValueTextSize(16f);
    pieData.setValueTextColor(Color.WHITE);
    return pieData;
}
项目:wakatime-android-client    文件:Charts.java   
public static PieChart defaultLanguageChart(List<Language> languages, PieChart chart, Linguist linguist) {
    chart.setCenterText(chart.getContext().getString(R.string.title_languages));

    List<PieEntry> dataSet = new ArrayList<>(languages.size());
    List<Integer> colors = new ArrayList<>(languages.size());

    for (Language language : languages) {
        dataSet.add(new PieEntry(language.getPercent(), language.getName()));
        int color = linguist.decode(language.getName());
        colors.add(color);
    }
    PieDataSet pieDataSet = new PieDataSet(dataSet, chart.getContext().getString(R.string.title_languages));
    pieDataSet.setValueTextColor(Color.WHITE);
    pieDataSet.setSliceSpace(3f);
    pieDataSet.setSelectionShift(5f);
    pieDataSet.setColors(colors);
    pieDataSet.setValueTextSize(14f);
    PieData pieData = new PieData(pieDataSet);
    pieData.setValueFormatter(new PercentFormatter());
    chart.setData(pieData);
    return chart;
}
项目:wakatime-android-client    文件:Charts.java   
public static PieChart defaultOSChart(List<OperatingSystem> operatingSystems, PieChart chart, Linguist linguist) {
    chart.setCenterText(chart.getContext().getString(R.string.title_os));

    List<PieEntry> entries = new ArrayList<>(operatingSystems.size());
    List<Integer> colors = new ArrayList<>(operatingSystems.size());
    for (OperatingSystem operatingSystem : operatingSystems) {
        entries.add(new PieEntry(operatingSystem.getPercent(), operatingSystem.getName()));
        colors.add(linguist.decodeOS(operatingSystem.getName()));
    }
    PieDataSet pieDataSet = new PieDataSet(entries, chart.getContext().getString(R.string.title_os));
    pieDataSet.setColors(colors);
    pieDataSet.setSliceSpace(3f);
    pieDataSet.setSelectionShift(5f);
    pieDataSet.setValueTextSize(14f);
    pieDataSet.setValueTextColor(Color.WHITE);
    PieData pieData = new PieData(pieDataSet);
    pieData.setValueFormatter(new PercentFormatter());
    chart.setData(pieData);
    return chart;
}
项目:wakatime-android-client    文件:Charts.java   
public static PieChart defaultEditorsChart(List<Editor> editors, PieChart chart) {
    chart.setCenterText(chart.getContext().getString(R.string.title_editors));
    int size = 0;
    if (editors != null) {
        size = editors.size();
    }
    List<PieEntry> dataSet = new ArrayList<>(size);
    //noinspection Convert2streamapi
    for (Editor editor : editors) {
        dataSet.add(new PieEntry(editor.getPercent(), editor.getName()));
    }

    PieDataSet pieDataSet = new PieDataSet(dataSet, chart.getContext().getString(R.string.title_editors));
    pieDataSet.setColors(ColorTemplate.JOYFUL_COLORS);
    pieDataSet.setValueTextColor(Color.WHITE);
    pieDataSet.setValueTextSize(14f);
    pieDataSet.setSliceSpace(3f);
    pieDataSet.setSelectionShift(5f);
    PieData pieData = new PieData(pieDataSet);
    pieData.setValueFormatter(new PercentFormatter());
    chart.setData(pieData);
    return chart;
}
项目:AmazeFileManager    文件:LoadFolderSpaceDataTask.java   
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);
}
项目:MPAndroidChart    文件:SimpleFragment.java   
/**
 * generates less data (1 DataSet, 4 values)
 * @return
 */
protected PieData generatePieData() {

    int count = 4;

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

    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;
}
项目:MPAndroidChart    文件:HalfPieChartActivity.java   
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.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(mTfLight);
        mChart.setData(data);

        mChart.invalidate();
    }
项目:MPAndroidChart    文件:ListViewMultiChartActivity.java   
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private PieData generateDataPie(int cnt) {

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

    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);

    PieData cd = new PieData(d);
    return cd;
}
项目:TumCampusApp    文件:GradesActivity.java   
private void showPieChart(List<Exam> exams){
    barChart.setVisibility(View.GONE);
    pieChart.setVisibility(View.VISIBLE);

    Map<String, Integer> gradeCount = calculateGradeDistribution(exams);

    List<PieEntry> entries = new ArrayList<>();
    for (String GRADE : GRADES) {
        entries.add(new PieEntry(gradeCount.get(GRADE), GRADE));
    }

    PieDataSet set = new PieDataSet(entries, getString(R.string.grades_without_weight));
    set.setColors(GRADE_COLORS, this);
    set.setDrawValues(false);

    pieChart.setData(new PieData(set));
    pieChart.setDrawEntryLabels(false);
    pieChart.getLegend().setWordWrapEnabled(true);
    pieChart.setDescription(null);
    pieChart.invalidate();
}
项目:CIA    文件:StatisticViewActivity.java   
private void addData() {
    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));
        xEntrys.add(xData[i]);
    }
    PieDataSet pieDataSet = new PieDataSet(yEntrys, "Category History");
    pieDataSet.setSliceSpace(2);
    pieDataSet.setValueTextSize(12);
    pieDataSet.setValueTextColor(Color.WHITE);
    ArrayList<Integer> colors = new ArrayList<>();
    colors.add(Color.RED);
    colors.add(Color.BLUE);
    pieDataSet.setColors(colors);
    Legend legend = pieChart.getLegend();

    List<LegendEntry> legends = new ArrayList<>();
    LegendEntry red = new LegendEntry();
    red.label = "Missed";
    red.formColor = Color.RED;
    legends.add(red);
    LegendEntry blue = new LegendEntry();
    blue.label = "Completed";
    blue.formColor = Color.BLUE;
    legends.add(blue);
    pieChart.getLegend().setCustom(legends);
    legend.setForm(Legend.LegendForm.CIRCLE);

    PieData pieData = new PieData(pieDataSet);
    pieChart.setData(pieData);
    pieChart.invalidate();
    pieChart.getDescription().setEnabled(false);
}
项目:CodeWatch    文件:ProjectDetailsFragment.java   
@Override
public void onValueSelected(Entry e, Highlight h) {
    Timber.d(e.toString());
    switch (CHART_ID) {
        case LANGUAGE_CHART_ID:
            if (!isExpandedMap.get(expandLanguages.getId())) {
                onExpand(expandLanguages);
            }
            languageHighlightedEntryX = h.getX();
            resetAdapter(languagesListview, languageListAdapter, ((PieEntry) e).getLabel());
            break;
        case OS_CHART_ID:
            if (!isExpandedMap.get(expandOs.getId())) {
                onExpand(expandOs);
            }
            osHighlightedEntryX = h.getX();
            resetAdapter(osListview, osListAdapter, ((PieEntry) e).getLabel());
            break;
        case EDITORS_CHART_ID:
            if (!isExpandedMap.get(expandEditors.getId())) {
                onExpand(expandEditors);
            }
            editorHighlightedEntryX = h.getX();
            resetAdapter(editorsListView, editorsListAdapter, ((PieEntry) e).getLabel());
            break;
        default: //common code
            break;
    }
}
项目:CodeWatch    文件:DashboardFragment.java   
@Override
public void onValueSelected(Entry e, Highlight h) {
    switch (CHART_ID) {
        case LANGUAGE_CHART_ID:
            if (!isExpandedMap.get(expandLanguages.getId())) {
                onExpand(expandLanguages);
            }
            languageHighlightedEntryX = h.getX();
            resetAdapter(languagesListview, languageListAdapter, ((PieEntry) e).getLabel());
            break;
        case OS_CHART_ID:
            if (!isExpandedMap.get(expandOs.getId())) {
                onExpand(expandOs);
            }
            osHighlightedEntryX = h.getX();
            resetAdapter(osListview, osListAdapter, ((PieEntry) e).getLabel());
            break;
        case EDITORS_CHART_ID:
            if (!isExpandedMap.get(expandEditors.getId())) {
                onExpand(expandEditors);
            }
            editorHighlightedEntryX = h.getX();
            resetAdapter(editorsListView, editorsListAdapter, ((PieEntry) e).getLabel());
            break;
        default: //common code
            break;
    }
}
项目:CodeWatch    文件:DashboardFragment.java   
@Override
public void onValueSelected(Entry e, Highlight h) {
    switch (CHART_ID) {
        case LANGUAGE_CHART_ID:
            if (!isExpandedMap.get(expandLanguages.getId())) {
                onExpand(expandLanguages);
            }
            languageHighlightedEntryX = h.getX();
            resetAdapter(languagesListview, languageListAdapter, ((PieEntry) e).getLabel());
            break;
        case OS_CHART_ID:
            if (!isExpandedMap.get(expandOs.getId())) {
                onExpand(expandOs);
            }
            osHighlightedEntryX = h.getX();
            resetAdapter(osListview, osListAdapter, ((PieEntry) e).getLabel());
            break;
        case EDITORS_CHART_ID:
            if (!isExpandedMap.get(expandEditors.getId())) {
                onExpand(expandEditors);
            }
            editorHighlightedEntryX = h.getX();
            resetAdapter(editorsListView, editorsListAdapter, ((PieEntry) e).getLabel());
            break;
        default: //common code
            break;
    }
}
项目:DOUSalaries    文件:DataBaseHelper.java   
/**Pies chart items*/

    private ChartItem buildPieChartItem(SQLiteDatabase db, long period,
                                        DemographicsType type, String title) {
        ChartItem result = null;
        Cursor cursor = buildCursorForCharts(type, db, period);
        try {
            if (cursor == null) {
                Timber.e("Error querying %s (got null cursor)", type.getName());
                return null;
            }
            if (cursor.getCount() < 1) {
                Timber.e("Error querying %s (no records returned)", type.getName());
                return null;
            }
            List<PieEntry> entries = new ArrayList<>();
            while (cursor.moveToNext()) {
                entries.add(new PieEntry( cursor.getFloat(1), cursor.getString(0)));
            }
            PieData chartData = ChartHelper.populatePieData(entries, "");
            result = new PieChartItem(context, chartData, title);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        return result;
    }
项目:DOUSalaries    文件:ChartHelper.java   
/**
 * Set the pie chart data source
 */
public static PieData populatePieData(List<PieEntry> entries, String label){
    PieDataSet dataSet = new PieDataSet(entries, label);
    dataSet.setSliceSpace(3f);
    dataSet.setSelectionShift(5f);
    //dataSet.setColors(populateColors());// add a lot of colors
    dataSet.setColors(ColorTemplate.MATERIAL_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.setValueTextSize(11f);
    return new PieData(dataSet);
}
项目:moneytracking    文件:ShowChartActivity.java   
private void init_chart_profit_expense() {
    pieChart = (PieChart) findViewById(R.id.show_chart_profitexpense);
    ArrayList<PieEntry> x = new ArrayList<>();
    ArrayList<Integer> colors = new ArrayList<>();

    x.add(new PieEntry(getDataExpenseProfit(start, end, 0), "Expense"));
    x.add(new PieEntry(getDataExpenseProfit(start, end, 1), "Profit"));

    colors.add(Color.RED);
    colors.add(Color.GREEN);

    createPieChart(x, colors);
}
项目:Opal-Chat-AnalyticsDashboard    文件:ChartData.java   
public static ArrayList<PieEntry> getPieData(int count, float range) {
    ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
    String[] mParties = new String[count];
    mParties[0] = "Week 1";
    mParties[1] = "Week 2";
    mParties[2] = "Week 3";
    mParties[3] = "Week 4";

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

    return entries;
}
项目:android-wallet-app    文件:NodeInfoFragment.java   
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();
    }
项目:AndroidQuiz    文件:AdapterEstatisticasGraph.java   
private void setupPie(PieChart pieChart, int pos, float dados[], String labels[]) {


        List<PieEntry> entries = new ArrayList<>();
        int index = 0;
        for (float dado : dados) {
            entries.add(new PieEntry(dado, labels[index]));
            index++;
        }

        //entries.add(new PieEntry(24.0f, "Red"));
        //entries.add(new PieEntry(30.8f, "Blue"));

        PieDataSet set = new PieDataSet(entries, "");
        Description description = new Description();
        description.setText(" ");
        pieChart.setDescription(description);
        set.setColors(ColorTemplate.MATERIAL_COLORS);
        PieData data = new PieData(set);
        pieChart.setData(data);
        pieChart.invalidate();


        Legend l = pieChart.getLegend();
        l.setFormSize(15f); // set the size of the legend forms/shapes
        l.setForm(Legend.LegendForm.CIRCLE); // set what type of form/shape should be used
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        l.setTextSize(18f);
        l.setTextColor(Color.BLACK);
        l.setXEntrySpace(5f); // set the space between the legend entries on the x-axis
        l.setYEntrySpace(5f);

        pieChart.animateXY(3000, 3000);

    }
项目:FaceT    文件:ProductDetailActivity.java   
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();
    }
项目:yield    文件:GraphicActivity.java   
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();
}
项目:RecipeFinderJavaVersion    文件:DiagramUtils.java   
public ArrayList<PieEntry> preparePieEntries(TotalNutrients nutrients) {
    ArrayList<PieEntry> entries = new ArrayList<>(3);
    if (nutrients.getProtein() != null)
        entries.add(new PieEntry((float) nutrients.getProtein().getQuantity(), nutrients.getProtein().getLabel()));
    if (nutrients.getFat() != null)
        entries.add(new PieEntry((float) nutrients.getFat().getQuantity(), nutrients.getFat().getLabel()));
    if (nutrients.getCarbs() != null)
        entries.add(new PieEntry((float) nutrients.getCarbs().getQuantity(), nutrients.getCarbs().getLabel()));

    return entries;
}
项目:RecipeFinderJavaVersion    文件:IngredientAnalysisViewModel.java   
private void prepareDiagramData(TotalNutrients nutrients) {
    if (nutrients == null)
        return;

    ArrayList<PieEntry> entries = diagramUtils.preparePieEntries(nutrients);
    diagramVisibility.set(entries.isEmpty() ? View.GONE : View.VISIBLE);
    PieDataSet pieDataSet = diagramUtils.createPieDataSet(entries, "Nutrients", null);
    PieData pieData = diagramUtils.createPieData(pieDataSet);

    onIngredientAnalyzedListener.onIngredientAnalyzed(pieData);
    diagramVisibility.set(View.VISIBLE);
}
项目:wakatime-android-client    文件:ProjectFragment.java   
private void setChartData(List<Project> chardData) {
    Typeface lato = Typeface.createFromAsset(this.getContext().getAssets(), "fonts/Lato-Regular.ttf");
    this.mChartProjects.setDrawHoleEnabled(true);
    this.mChartProjects.setHoleColor(Color.WHITE);
    this.mChartProjects.setTransparentCircleColor(Color.WHITE);
    this.mChartProjects.setTransparentCircleAlpha(110);
    this.mChartProjects.setDragDecelerationFrictionCoef(0.95f);
    this.mChartProjects.setHoleRadius(58f);
    this.mChartProjects.setTransparentCircleRadius(61f);
    this.mChartProjects.setDescription("");
    this.mChartProjects.setUsePercentValues(true);
    this.mChartProjects.setEntryLabelColor(Color.WHITE);
    this.mChartProjects.setDrawCenterText(true);
    this.mChartProjects.setCenterText(getString(R.string.title_projects));
    this.mChartProjects.setCenterTextSize(18f);
    this.mChartProjects.setEntryLabelTypeface(lato);
    this.mChartProjects.setCenterTextTypeface(lato);
    this.mChartProjects.setCenterTextColor(getColor(getActivity(), R.color.colorSecondaryText));
    this.mChartProjects.animateY(1400, Easing.EasingOption.EaseInOutQuad);
    enableNestingScrollForAP21();

    List<PieEntry> entries = new ArrayList<>(chardData.size());
    for (Project project : chardData) {
        entries.add(new PieEntry(project.getPercent(), project.getName()));
    }
    PieDataSet pieDataSet = new PieDataSet(entries, getString(R.string.title_projects));
    pieDataSet.setHighlightEnabled(true);
    pieDataSet.setValueTextColor(Color.WHITE);
    pieDataSet.setValueTextSize(14f);
    pieDataSet.setColors(ColorTemplate.VORDIPLOM_COLORS);
    pieDataSet.setSliceSpace(3f);
    pieDataSet.setSelectionShift(5f);
    PieData pieData = new PieData(pieDataSet);
    pieData.setValueFormatter(new PercentFormatter());
    this.mChartProjects.setData(pieData);
}
项目:stately    文件:PieChartListener.java   
@Override
public void onValueSelected(Entry e, Highlight h) {
    if (pieChart != null) {
        PieEntry entry = (PieEntry) e;
        pieChart.setCenterText(
                String.format(Locale.US, INNER_TEXT_TEMPLATE,
                        entry.getLabel(),
                        SparkleHelper.getPrettifiedNumber(entry.getValue())
                )
        );
    }
}
项目:plus-one    文件:ChartFragment.java   
private void drawPie() {
    ArrayList<PieEntry> entries = new ArrayList<>();

    for (OptionModel choice: poll.getOptionModels()) {
        entries.add(new PieEntry(Float.valueOf(choice.getVote()), choice.getContent()));
    }

    PieDataSet dataSet = new PieDataSet(entries, " # of votes");
    dataSet.setColors(ColorTemplate.COLORFUL_COLORS);

    PieData data = new PieData(dataSet);
    pieChart.setData(data);
}
项目:outlay    文件:ReportAdapter.java   
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();
}