本文整理汇总了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");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}