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

项目:GitHub    文件:RealmDatabaseActivityPie.java   
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();

        RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "yValue", "label");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setLabel("Example market share");
        set.setSliceSpace(2);

        // create a data object with the dataset list
        PieData data = new PieData(set);
        styleData(data);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(12f);

        // set data
        mChart.setData(data);
        mChart.animateY(1400);
    }
项目: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();
    }
项目:Stayfit    文件:ListViewMultiChartActivity.java   
/**
 * 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;
}
项目: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);

    }
}
项目:P2P    文件:PieChartActivity.java   
/**
 * 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;
}
项目:Sxumiro_AndroidClient    文件:ListViewMultiChartFragment.java   
/**
 * 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;
}
项目: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    文件:RealmDatabaseActivityPie.java   
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();

        RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "yValue", "label");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setLabel("Example market share");
        set.setSliceSpace(2);

        // create a data object with the dataset list
        PieData data = new PieData(set);
        styleData(data);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(12f);

        // set data
        mChart.setData(data);
        mChart.animateY(1400);
    }
项目: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;
}
项目: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;
}
项目:SampleApp    文件:DashboardFragment.java   
public PieData createPieChartData()
{
    List<Entry> entries = new ArrayList<>();
    entries.add(new Entry(50, 0));
    entries.add(new Entry(25, 1));
    entries.add(new Entry(12.5f, 2));
    entries.add(new Entry(12.5f, 3));

    PieDataSet data = new PieDataSet(entries, null);
    data.setDrawValues(false);
    data.setColors(new int[] {
            0xFF673ab7, 0xFF2196f3, 0xFF4caf50, 0xFF009688
    });

    String[] labels = new String[] {"Blackberry", "Blueberry", "Green apple", "Seaweed"};

    return new PieData(labels, data);
}
项目:ResearchStack    文件:PieChartCard.java   
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);
    }
}
项目:mobile-manager-for-cloudflare    文件:AnalyticsFragment.java   
/**
 * Initializes the PieChart with the given parameters. Automatically hides description and adds animation.
 *
 * @param chart: PieChart object defined in XML layout
 * @param colorTemplate: int[] array of colors, where each color is a resource, i.e. R.color.green
 * @param data: HashMap of section name label to value, i.e. "Yes": 40, "No": 60
 */
public void initializeChart(PieChart chart, int[] colorTemplate, HashMap<String, Integer> data) {
    // Add y-values from data to the pie chart data set
    ArrayList<Entry> values = new ArrayList<Entry>();
    int index = 0;
    for (int value : data.values())
        values.add(new Entry(value, index++));
    PieDataSet dataSet = new PieDataSet(values, "");

    // Create section labels and disable x-value labels
    chart.setData(new PieData(new ArrayList<String>(data.keySet()), dataSet));
    chart.setDrawXValues(false);

    // Add colors from color template
    dataSet.setColors(colorTemplate);

    // Hide description and legend
    chart.setDescription("");
    chart.setDrawLegend(false);

    // Add animation
    chart.animateXY(1500, 1500);
}
项目:Mi-Band    文件:SleepChartActivity.java   
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();
}
项目:eCarNet    文件:PieChartCustom.java   
public PieChartCustom(PieChart graphical, ArrayList<Entry> entries, String entriesLegend, ArrayList<String> labels, String chartDecription)
{
    this.entries = entries;
    this.chart = graphical;
    this.dataset = new PieDataSet(entries, entriesLegend);
    this.data = new PieData(labels, this.dataset);
    this.colors = new ArrayList<>();
    //chart.setTouchEnabled(false);
    this.legend = chart.getLegend();
    if(chartDecription!= null)
        chart.setDescription(chartDecription);
    else chart.setDescription("");
    float sum = 0f;
    for(int i = 0; i<entries.size(); i++)
    {
        sum += entries.get(i).getVal();
    }
    this.chart.setCenterText(String.format("%1$s\n%2$.2f", "Total", sum));
    this.chart.setCenterTextSize(16);
    Paint text = new Paint();
    text.setTextAlign(Paint.Align.CENTER);
    this.chart.setPaint(text, Chart.PAINT_CENTER_TEXT);
    this.chart.setUsePercentValues(true);
    setDefaultChart();
    setDefaultLegend();
}
项目: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    文件:RealmDatabaseActivityPie.java   
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();

        RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "yValue", "label");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setLabel("Example market share");
        set.setSliceSpace(2);

        // create a data object with the dataset list
        PieData data = new PieData(set);
        styleData(data);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(12f);

        // set data
        mChart.setData(data);
        mChart.animateY(1400);
    }
项目: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;
}
项目:what-stored-in-a-mobile-device-android    文件:Graphs.java   
private void setSizePieChart() {
    PieChart pieChart = (PieChart) findViewById(R.id.size_pie_chart);
    ArrayList<Entry> yVals = new ArrayList<Entry>();
    yVals.add(new Entry(totalSize(DeviceDataContract.VideoDataEntry.TABLE_NAME, VideoDataCollector.videoColumnNames), 0));
    yVals.add(new Entry(totalSize(DeviceDataContract.ImageDataEntry.TABLE_NAME, ImageDataCollector.imageColumnNames), 1));
    yVals.add(new Entry(totalSize(DeviceDataContract.AudioDataEntry.TABLE_NAME, AudioDataCollector.audioColumnNames), 2));
    yVals.add(new Entry(totalSize(DeviceDataContract.TextDataEntry.TABLE_NAME, TextDataCollector.textColumnNames), 3));
    ArrayList<String> xVals = new ArrayList<String>();
    xVals.add("Videos (kB)");
    xVals.add("Images (kB)");
    xVals.add("Audio (kB)");
    xVals.add("Text files (kB)");

    PieDataSet pieDataSet = new PieDataSet(yVals, "");
    int[] colorsi = new int[] {R.color.red, R.color.blue, R.color.yellow, R.color.green} ;
    pieDataSet.setColors(colorsi, this);
    PieData data = new PieData(xVals, pieDataSet);
    pieChart.setDescription("");
    pieChart.setData(data);
}
项目:what-stored-in-a-mobile-device-android    文件:Graphs.java   
private void setCountPieChart() {
    PieChart pieChart = (PieChart) findViewById(R.id.count_pie_chart);
    ArrayList<Entry> yVals = new ArrayList<Entry>();
    yVals.add(new Entry(count(DeviceDataContract.VideoDataEntry.TABLE_NAME, VideoDataCollector.videoColumnNames), 0));
    yVals.add(new Entry(count(DeviceDataContract.ImageDataEntry.TABLE_NAME, ImageDataCollector.imageColumnNames), 1));
    yVals.add(new Entry(count(DeviceDataContract.AudioDataEntry.TABLE_NAME, AudioDataCollector.audioColumnNames), 2));
    yVals.add(new Entry(count(DeviceDataContract.TextDataEntry.TABLE_NAME, TextDataCollector.textColumnNames), 3));
    yVals.add(new Entry(count(DeviceDataContract.ApplicationDataEntry.TABLE_NAME, ApplicationDataCollector.applicationDataColumnNames), 4));
    ArrayList<String> xVals = new ArrayList<String>();
    xVals.add("Videos");
    xVals.add("Images");
    xVals.add("Audio");
    xVals.add("Text files");
    xVals.add("Applications");

    PieDataSet pieDataSet = new PieDataSet(yVals, "");
    int[] colorsi = new int[] {R.color.red, R.color.blue, R.color.yellow, R.color.green} ;
    pieDataSet.setColors(colorsi, this);
    PieData data = new PieData(xVals, pieDataSet);
    pieChart.setDescription("");
    pieChart.setData(data);

}
项目: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);
}
项目:GitHub    文件:PieChartRenderer.java   
@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);
    }
}
项目: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 pattern
 * @param pieChart chart
 * @param chartData pie chart data
 * @param title chart title
 * @param tf Typeface font
 */
public static void setPieChart(PieChart pieChart, ChartData<?> chartData,
                               SpannableString title, Typeface tf) {
    chartData.setValueFormatter(new PercentFormatter());
    chartData.setValueTextSize(11f);
    chartData.setValueTextColor(Color.BLACK);
    chartData.setValueTypeface(tf);

    pieChart.setUsePercentValues(true);
    pieChart.getDescription().setEnabled(false);
    pieChart.setExtraOffsets(5, 10, 5, 5);
    pieChart.setDragDecelerationFrictionCoef(0.95f);
    pieChart.setCenterTextTypeface(tf);
    pieChart.setCenterText(title);
    pieChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
    pieChart.setDrawHoleEnabled(true);
    pieChart.setHoleColor(Color.WHITE);
    pieChart.setTransparentCircleColor(Color.WHITE);
    pieChart.setTransparentCircleAlpha(110);
    pieChart.setHoleRadius(58f);
    pieChart.setTransparentCircleRadius(61f);
    pieChart.setDrawCenterText(true);
    pieChart.setRotationAngle(0);
    pieChart.setRotationEnabled(true);// enable rotation of the chart by touch
    pieChart.setHighlightPerTapEnabled(true);
    pieChart.setEntryLabelTextSize(10f);

    Legend l = pieChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setEnabled(false);

    pieChart.setData((PieData) chartData);
    pieChart.animateY(DURATION_MEDIUM, Easing.EasingOption.EaseInOutQuad);
    pieChart.highlightValues(null);// undo all highlights
    pieChart.invalidate();

}
项目: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);
}
项目:BrainPhaser    文件:ChartDataLogic.java   
/**
 * 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;
}
项目:BrainPhaser    文件:ChartDataLogic.java   
/**
 * 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;
}