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

The following are top voted examples for showing how to use com.github.mikephil.charting.data.PieData. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: SimpleFragment.java   Source Code and License 7 votes vote down vote up
/**
 * 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;
}
 
Example 2
Project: GitHub   File: RealmDatabaseActivityPie.java   Source Code and License 7 votes vote down vote up
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);
    }
 
Example 3
Project: DOUSalaries   File: DataBaseHelper.java   Source Code and License 7 votes vote down vote up
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;
}
 
Example 4
Project: GitHub   File: HalfPieChartActivity.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 5
Project: GitHub   File: ListViewMultiChartActivity.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Project: CodeWatch   File: ChartFragment.java   Source Code and License 6 votes vote down vote up
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;
    }
 
Example 7
Project: DOUSalaries   File: ChartHelper.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 8
Project: moneytracking   File: ShowChartActivity.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 9
Project: Opal-Chat-AnalyticsDashboard   File: DashboardFragment.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 10
Project: Stayfit   File: ListViewMultiChartActivity.java   Source Code and License 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 11
Project: android-wallet-app   File: NodeInfoFragment.java   Source Code and License 6 votes vote down vote up
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 12
Project: shorl   File: DetailActivity.java   Source Code and License 6 votes vote down vote up
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);

    }
}
 
Example 13
Project: P2P   File: PieChartActivity.java   Source Code and License 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 14
Project: Sxumiro_AndroidClient   File: ListViewMultiChartFragment.java   Source Code and License 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 15
Project: xs-android-architecture   File: SimpleFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 16
Project: xs-android-architecture   File: HalfPieChartActivity.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 17
Project: xs-android-architecture   File: RealmDatabaseActivityPie.java   Source Code and License 6 votes vote down vote up
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);
    }
 
Example 18
Project: xs-android-architecture   File: ListViewMultiChartActivity.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 19
Project: wakatime-android-client   File: LeaderProfileFragment.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 20
Project: wakatime-android-client   File: Charts.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 21
Project: wakatime-android-client   File: Charts.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 22
Project: wakatime-android-client   File: Charts.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 23
Project: SampleApp   File: DashboardFragment.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 24
Project: ResearchStack   File: PieChartCard.java   Source Code and License 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 25
Project: mobile-manager-for-cloudflare   File: AnalyticsFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 26
Project: Mi-Band   File: SleepChartActivity.java   Source Code and License 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 27
Project: eCarNet   File: PieChartCustom.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 28
Project: AmazeFileManager   File: LoadFolderSpaceDataTask.java   Source Code and License 6 votes vote down vote up
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 29
Project: MPAndroidChart   File: SimpleFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 30
Project: MPAndroidChart   File: HalfPieChartActivity.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 31
Project: MPAndroidChart   File: RealmDatabaseActivityPie.java   Source Code and License 6 votes vote down vote up
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);
    }
 
Example 32
Project: MPAndroidChart   File: ListViewMultiChartActivity.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 33
Project: what-stored-in-a-mobile-device-android   File: Graphs.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 34
Project: what-stored-in-a-mobile-device-android   File: Graphs.java   Source Code and License 6 votes vote down vote up
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);

}
 
Example 35
Project: TumCampusApp   File: GradesActivity.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 36
Project: CIA   File: StatisticViewActivity.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 37
Project: GitHub   File: PieChartRenderer.java   Source Code and 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 38
Project: DOUSalaries   File: DataBaseHelper.java   Source Code and License 5 votes vote down vote up
/**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;
    }
 
Example 39
Project: DOUSalaries   File: ChartHelper.java   Source Code and License 5 votes vote down vote up
/**
 * 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();

}
 
Example 40
Project: BrainPhaser   File: ChartDataLogic.java   Source Code and License 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;
}