當前位置: 首頁>>代碼示例>>Java>>正文


Java PieChart.setData方法代碼示例

本文整理匯總了Java中com.github.mikephil.charting.charts.PieChart.setData方法的典型用法代碼示例。如果您正苦於以下問題:Java PieChart.setData方法的具體用法?Java PieChart.setData怎麽用?Java PieChart.setData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.mikephil.charting.charts.PieChart的用法示例。


在下文中一共展示了PieChart.setData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUpPieChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
/**
 * @param pieChart  that needs to be setup
 * @param chartData data that will displayed on the chart
 * @param chartType type of the chart
 */
public void setUpPieChart(PieChart pieChart, Map<String, Integer> chartData, @PieChartType int chartType) {
    formatPieChart(pieChart);
    formatPieChartLegend(pieChart.getLegend());
    List<PieChartItem> pieChartItems = setUpData(chartData);
    pieChart.setData(generatePieData(pieChartItems));
    pieChart.highlightValues(null);

    switch (chartType) {
        case LANGUAGE_CHART_ID:
            languageDataItems = pieChartItems;
            break;
        case EDITORS_CHART_ID:
            editorDataItems = pieChartItems;
            break;
        case OS_CHART_ID:
            osDataItems = pieChartItems;
            break;
        default:
            throw new UnsupportedOperationException("Invalid chart type");
    }
}
 
開發者ID:Protino,項目名稱:CodeWatch,代碼行數:27,代碼來源:ChartFragment.java

示例2: onCreateView

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_pie, container, false);
    
    mChart = (PieChart) v.findViewById(R.id.pieChart1);
    mChart.setDescription("");
    
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
    
    mChart.setCenterTextTypeface(tf);
    mChart.setCenterText(generateCenterText());
    mChart.setCenterTextSize(10f);
    mChart.setCenterTextTypeface(tf);
     
    // radius of the center hole in percent of maximum radius
    mChart.setHoleRadius(45f);
    mChart.setTransparentCircleRadius(50f);
    
    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    
    mChart.setData(generatePieData());
    
    return v;
}
 
開發者ID:rahulmaddineni,項目名稱:Stayfit,代碼行數:26,代碼來源:PieChartFrag.java

示例3: defaultLanguageChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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;
}
 
開發者ID:omgitsjoao,項目名稱:wakatime-android-client,代碼行數:23,代碼來源:Charts.java

示例4: defaultOSChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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;
}
 
開發者ID:omgitsjoao,項目名稱:wakatime-android-client,代碼行數:21,代碼來源:Charts.java

示例5: defaultEditorsChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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;
}
 
開發者ID:omgitsjoao,項目名稱:wakatime-android-client,代碼行數:24,代碼來源:Charts.java

示例6: initializeChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:LINKIWI,項目名稱:mobile-manager-for-cloudflare,代碼行數:30,代碼來源:AnalyticsFragment.java

示例7: setSizePieChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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);
}
 
開發者ID:TeamWhat,項目名稱:what-stored-in-a-mobile-device-android,代碼行數:21,代碼來源:Graphs.java

示例8: setCountPieChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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);

}
 
開發者ID:TeamWhat,項目名稱:what-stored-in-a-mobile-device-android,代碼行數:24,代碼來源:Graphs.java

示例9: onCreateView

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_pie, container, false);
    
    mChart = (PieChart) v.findViewById(R.id.pieChart1);
    mChart.getDescription().setEnabled(false);
    
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
    
    mChart.setCenterTextTypeface(tf);
    mChart.setCenterText(generateCenterText());
    mChart.setCenterTextSize(10f);
    mChart.setCenterTextTypeface(tf);
     
    // radius of the center hole in percent of maximum radius
    mChart.setHoleRadius(45f);
    mChart.setTransparentCircleRadius(50f);
    
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    
    mChart.setData(generatePieData());
    
    return v;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:PieChartFrag.java

示例10: setPieChart

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
/**
 * 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();

}
 
開發者ID:graviton57,項目名稱:DOUSalaries,代碼行數:47,代碼來源:ChartHelper.java

示例11: setupPie

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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);

    }
 
開發者ID:ivoribeiro,項目名稱:AndroidQuiz,代碼行數:39,代碼來源:AdapterEstatisticasGraph.java

示例12: setChartData

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
private void setChartData(PieChart chart, List<Integer> yData) {
    ArrayList<Entry> yVals = new ArrayList<>();

    for (int i = 0; i < yData.size(); ++i) {
        yVals.add(new Entry(yData.get(i), i));
    }

    ArrayList<String> xVals = new ArrayList<>();

    for (int i = 0; i < xData.length; ++i) {
        xVals.add(xData[i]);
    }

    PieDataSet dataSet = new PieDataSet(yVals, "");
    dataSet.setSliceSpace(3);
    dataSet.setSelectionShift(5);

    ArrayList<Integer> colors = new ArrayList<>();

    colors.add(0xFFDD2C00);
    colors.add(0xFFFF6D00);
    colors.add(0xFFFFAB00);
    colors.add(0xFFAEEA00);
    colors.add(0xFF64DD17);

    dataSet.setColors(colors);

    PieData data = new PieData(xVals, dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(15f);
    data.setValueTextColor(Color.BLACK);
    chart.setData(data);
    chart.highlightValues(null);
    chart.invalidate();
}
 
開發者ID:kaiomax,項目名稱:RUSpotlight,代碼行數:36,代碼來源:StatisticsFragment.java

示例13: setData

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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();
    }
 
開發者ID:clementf2b,項目名稱:FaceT,代碼行數:39,代碼來源:ProductDetailActivity.java

示例14: updateChartData

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
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();
}
 
開發者ID:bmelnychuk,項目名稱:outlay,代碼行數:28,代碼來源:ReportAdapter.java

示例15: onCreate

import com.github.mikephil.charting.charts.PieChart; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

PieChart pieChart = (PieChart)findViewById(R.id.chart);


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

    entries.add(new Entry(4f,0));
    entries.add(new Entry(8f,1));
    entries.add(new Entry(6f,2));
    entries.add(new Entry(12f,3));
   // entries.add(new Entry(18f,4));
 //   entries.add(new Entry(9f,0));

    PieDataSet dataset = new PieDataSet(entries, "# of calls");

    ArrayList<String> labels = new ArrayList<String>();
    labels.add("January");
    labels.add("February");
    labels.add("March");
    labels.add("April");
 //   labels.add("May");
   // labels.add("June");

    PieData data = new PieData(labels, dataset); // initialize Piedata
    pieChart.setData(data);

    pieChart.setDescription("Description");
     dataset.setColors(ColorTemplate.COLORFUL_COLORS);
    pieChart.animateY(2000);


}
 
開發者ID:NikhilBhutani,項目名稱:Android-Snippets,代碼行數:37,代碼來源:MainActivity.java


注:本文中的com.github.mikephil.charting.charts.PieChart.setData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。