本文整理汇总了Java中com.github.mikephil.charting.charts.PieChart类的典型用法代码示例。如果您正苦于以下问题:Java PieChart类的具体用法?Java PieChart怎么用?Java PieChart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PieChart类属于com.github.mikephil.charting.charts包,在下文中一共展示了PieChart类的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: formatPieChart
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
private void formatPieChart(PieChart pieChart) {
pieChart.setUsePercentValues(true);
pieChart.getDescription().setEnabled(false);
pieChart.setDrawHoleEnabled(true);
pieChart.setHoleColor(context.getResources().getColor(R.color.colorPrimaryDark));
pieChart.setTransparentCircleColor(Color.GRAY);
pieChart.setTransparentCircleAlpha(110);
pieChart.setRotationAngle(0);
pieChart.setRotationEnabled(true);
pieChart.setHighlightPerTapEnabled(true);
pieChart.setEntryLabelColor(Color.WHITE);
pieChart.setDrawEntryLabels(false);
pieChart.setBackground(context.getResources().getDrawable(R.color.colorPrimaryDark));
}
示例3: applyMostPlayedChart
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
/**
* Applies a most played / failed / succeeded chart to the chart in the mItemView view
*
* @param type the statistic type of the chart to be applied
*/
public void applyMostPlayedChart(StatisticType type) {
//Apply chart
PieChart chart = (PieChart) mItemView.findViewById(R.id.statisticsChart);
mShownChallenges = mStatisticsLogic.fillChart(chart, type);
//Add chart selection listener
chart.setOnChartValueSelectedListener(new ChartValueSelectedListener(this));
//Select first entry
if (chart.getData() != null) {
chart.highlightValue(0, 0);
TextView text = (TextView) mItemView.findViewById(R.id.challengeView);
String question = mChallengeDataSource.getById(mShownChallenges.get(0)).getQuestion();
if (text != null) text.setText(question);
}
TextView title = (TextView) mItemView.findViewById(R.id.titleView);
if (title != null) title.setText(getTitle(type));
}
示例4: PieChartRenderer
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
public PieChartRenderer(PieChart chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHolePaint.setColor(Color.WHITE);
mHolePaint.setStyle(Style.FILL);
mTransparentCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTransparentCirclePaint.setColor(Color.WHITE);
mTransparentCirclePaint.setStyle(Style.FILL);
mTransparentCirclePaint.setAlpha(105);
mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mCenterTextPaint.setColor(Color.BLACK);
mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
mValuePaint.setColor(Color.WHITE);
mValuePaint.setTextAlign(Align.CENTER);
}
示例5: 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;
}
示例6: PieChartRenderer
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
public PieChartRenderer(PieChart chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHolePaint.setColor(Color.WHITE);
mHolePaint.setStyle(Style.FILL);
mTransparentCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTransparentCirclePaint.setColor(Color.WHITE);
mTransparentCirclePaint.setStyle(Style.FILL);
mTransparentCirclePaint.setAlpha(105);
mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mCenterTextPaint.setColor(Color.BLACK);
mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
mValuePaint.setColor(Color.WHITE);
mValuePaint.setTextAlign(Align.CENTER);
mValueLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mValueLinePaint.setStyle(Style.STROKE);
}
示例7: PieChartRenderer
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
public PieChartRenderer(PieChart chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
mChart = chart;
mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHolePaint.setColor(Color.WHITE);
mHolePaint.setStyle(Style.FILL);
mTransparentCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTransparentCirclePaint.setColor(Color.WHITE);
mTransparentCirclePaint.setStyle(Style.FILL);
mTransparentCirclePaint.setAlpha(100);
mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mCenterTextPaint.setColor(Color.BLACK);
mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
mCenterTextPaint.setTextAlign(Align.CENTER);
mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
mValuePaint.setColor(Color.WHITE);
mValuePaint.setTextAlign(Align.CENTER);
}
示例8: updateChartReference
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
private void updateChartReference(final String mealKey, final PieChart chart) {
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("meals").child(mealKey);
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
GenericTypeIndicator<Map<String, Integer>> t = new GenericTypeIndicator<Map<String, Integer>>() {};
Map<String, Integer> ratings = dataSnapshot.child("ratings").getValue(t);
if( ratings == null ) {
clearChartData(chart);
}
else {
setChartData(chart, calculateRatings(ratings));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例9: setDefaultPieChartConfig
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
public static PieChart setDefaultPieChartConfig(PieChart chart) {
chart.setDrawHoleEnabled(true);
chart.setHoleColor(Color.WHITE);
chart.setTransparentCircleColor(Color.WHITE);
chart.setTransparentCircleAlpha(110);
chart.setDragDecelerationFrictionCoef(0.95f);
chart.setHoleRadius(58f);
chart.setTransparentCircleRadius(61f);
chart.setDescription("");
chart.setUsePercentValues(true);
chart.setEntryLabelColor(Color.WHITE);
chart.setDrawCenterText(true);
chart.setCenterTextSize(18f);
chart.setCenterTextColor(ContextCompat.getColor(chart.getContext(), R.color.colorSecondaryText));
chart.setRotationAngle(0);
chart.setRotationEnabled(true);
chart.setHighlightPerTapEnabled(true);
chart.setMaxHighlightDistance(400f);
chart.setCenterTextTypeface(Typeface.createFromAsset(chart.getContext().getAssets(), "fonts/Lato-Regular.ttf"));
chart.setEntryLabelTypeface(Typeface.createFromAsset(chart.getContext().getAssets(), "fonts/Lato-Regular.ttf"));
chart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
return chart;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: PollCard
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
public PollCard(View v) {
super(v);
question = (TextView) v.findViewById(R.id.card_region_poll_question);
content = (HtmlTextView) v.findViewById(R.id.card_region_poll_content);
author = (TextView) v.findViewById(R.id.card_region_poll_author);
open = (TextView) v.findViewById(R.id.card_region_poll_open);
close = (TextView) v.findViewById(R.id.card_region_poll_close);
options = (LinearLayout) v.findViewById(R.id.card_region_poll_options);
breakdown = (PieChart) v.findViewById(R.id.card_region_poll_chart);
nullVote = (TextView) v.findViewById(R.id.region_poll_null_vote);
divider = v.findViewById(R.id.view_divider);
voteButton = (LinearLayout) v.findViewById(R.id.card_region_poll_vote_button);
voteButtonIcon = (ImageView) v.findViewById(R.id.card_region_poll_icon);
voteButtonProgress = (ProgressBar) v.findViewById(R.id.card_region_poll_progressbar);
voteButtonContent = (TextView) v.findViewById(R.id.card_region_poll_vote_button_content);
}
示例14: ZombieChartCard
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
public ZombieChartCard(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.card_zombie_chart_title);
action = (TextView) itemView.findViewById(R.id.card_zombie_chart_action);
nullData = (TextView) itemView.findViewById(R.id.card_zombie_chart_null);
chart = (PieChart) itemView.findViewById(R.id.card_zombie_chart);
divider = itemView.findViewById(R.id.view_divider);
genericButton = (LinearLayout) itemView.findViewById(R.id.card_zombie_chart_button_generic);
genericButtonIcon = (ImageView) itemView.findViewById(R.id.card_zombie_chart_button_generic_icon);
genericButtonText = (TextView) itemView.findViewById(R.id.card_zombie_chart_button_generic_text);
missileButton = (LinearLayout) itemView.findViewById(R.id.card_zombie_chart_button_missile);
missileIcon = (ImageView) itemView.findViewById(R.id.card_zombie_chart_missile_icon);
missileProgressBar = (ProgressBar) itemView.findViewById(R.id.card_zombie_chart_missile_progressbar);
}
示例15: onCreateView
import com.github.mikephil.charting.charts.PieChart; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
mActivityChart = (CombinedChart) rootView.findViewById(R.id.sleepchart);
mSleepAmountChart = (PieChart) rootView.findViewById(R.id.sleepchart_pie_light_deep);
setupActivityChart();
setupSleepAmountChart();
// refresh immediately instead of use refreshIfVisible(), for perceived performance
refresh();
return rootView;
}