SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
SciChart Android ships with ~90Â Android Chart Examples which you can browse, play with, view the source-code and even export each SciChart Android Chart Example to a stand-alone Android Studio project. All of this is possible with the new and improved SciChart Android Examples Suite, which ships as part of our Android Charts SDK.
This example demonstrates how to create an Android Pie Chart in code.
See Documentation on how to use this type here:
The Android Pie Chart Documentation.
The SciPieChartSurface can be used to render either Pie, Donut or Nested Pie charts in Java.
Pie charts can be animated on show, have legends and support selection of segments, as well as showing and hiding of labels. Data is provided by a number of PieSegments, which are stored in a IPieRenderableSeries.
The full source code for the Android Pie Chart example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2017. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// PieChartFragment.java is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
//******************************************************************************
package com.scichart.examples.fragments;
import com.scichart.charting.modifiers.PieSegmentSelectionModifier;
import com.scichart.charting.visuals.SciPieChartSurface;
import com.scichart.charting.visuals.legend.SciChartLegend;
import com.scichart.charting.visuals.renderableSeries.IPieRenderableSeries;
import com.scichart.examples.R;
import com.scichart.examples.fragments.base.ExampleBaseFragment;
import java.util.Collections;
import butterknife.BindView;
public class PieChartFragment extends ExampleBaseFragment {
@BindView(R.id.pieChart)
SciPieChartSurface pieChartSurface;
@BindView(R.id.pieChartLegend)
SciChartLegend legend;
@Override
protected int getLayoutId() {
return R.layout.example_single_pie_chart_with_legend_fragment;
}
@Override
protected void initExample() {
final IPieRenderableSeries pieSeries = sciChartBuilder.newPieSeries().withSegments(
sciChartBuilder.newPieSegment().withValue(40).withTitle("Green").withRadialGradientColors(0xff84BC3D, 0xff5B8829).build(),
sciChartBuilder.newPieSegment().withValue(10).withTitle("Red").withRadialGradientColors(0xffe04a2f, 0xffB7161B).build(),
sciChartBuilder.newPieSegment().withValue(20).withTitle("Blue").withRadialGradientColors(0xff4AB6C1, 0xff2182AD).build(),
sciChartBuilder.newPieSegment().withValue(15).withTitle("Yellow").withRadialGradientColors(0xffFFFF00, 0xfffed325).build()
).build();
Collections.addAll(pieChartSurface.getRenderableSeries(), pieSeries);
Collections.addAll(pieChartSurface.getChartModifiers(), sciChartBuilder.newLegendModifier(legend).withSourceSeries(pieSeries).build(), new PieSegmentSelectionModifier());
pieSeries.animate(800);
}
}