Android Chart - Examples
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 Nested Chart in code.
See Documentation on how to use this type here:
The Android Nested Chart Documentation.
The SciPieChartSurface can be used to render either Pie, Donut or Nested Pie charts in Java.
Nested 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 Nested 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?
- Clone the SciChart.Android.Examples from Github.
- Or, view source and export each example to an Android Studio project from the Java version of the SciChart Android Examples app.
- Also the SciChart Android Trial contains the full source for the examples (link below).
Kotlin: MultiplePieDonutChartFragment.kt
View source code//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// MultiplePieDonutChartFragment.kt is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************
package com.scichart.examples.fragments.examples2d.createGaugeCharts.kt
import android.view.LayoutInflater
import com.scichart.charting.visuals.renderableSeries.DonutRenderableSeries
import com.scichart.charting.visuals.renderableSeries.PieRenderableSeries
import com.scichart.examples.databinding.ExampleSinglePieChartWithLegendFragmentBinding
import com.scichart.examples.fragments.base.ExampleBaseFragment
import com.scichart.examples.utils.Constant
import com.scichart.examples.utils.scichartExtensions.*
class MultiplePieDonutChartFragment : ExampleBaseFragment<ExampleSinglePieChartWithLegendFragmentBinding>() {
override fun inflateBinding(inflater: LayoutInflater): ExampleSinglePieChartWithLegendFragmentBinding {
return ExampleSinglePieChartWithLegendFragmentBinding.inflate(inflater)
}
override fun initExample(binding: ExampleSinglePieChartWithLegendFragmentBinding) {
val pieSeries = PieRenderableSeries().apply {
seriesName = "HowPeopleTravel"
segmentsCollection {
pieSegment { value = 34.0; title = "Ecologic"; fillStyle = RadialGradientBrushStyle(0xff68bcae, 0xff68bcae) }
pieSegment { value = 34.4; title = "Municipal"; fillStyle = RadialGradientBrushStyle(0xffe97064, 0xffe97064) }
pieSegment { value = 31.6; title = "Personal"; fillStyle = RadialGradientBrushStyle(0xff47bde6, 0xff47bde6) }
}
}
val donutSeries = DonutRenderableSeries().apply {
seriesName = "DetailedGroup"
segmentsCollection {
pieSegment { value = 28.8; title = "Walking"; fillStyle = RadialGradientBrushStyle(0xff68bcae, 0xff68bcae) }
pieSegment { value = 5.2; title = "Bicycle"; fillStyle = RadialGradientBrushStyle(0xff68bcae, 0xff68bcae) }
pieSegment { value = 12.3; title = "Metro"; fillStyle = RadialGradientBrushStyle(0xffe97064, 0xffe97064) }
pieSegment { value = 3.5; title = "Tram"; fillStyle = RadialGradientBrushStyle(0xffe97064, 0xffe97064) }
pieSegment { value = 5.9; title = "Rail"; fillStyle = RadialGradientBrushStyle(0xffe97064, 0xffe97064) }
pieSegment { value = 9.7; title = "Bus"; fillStyle = RadialGradientBrushStyle(0xffe97064, 0xffe97064) }
pieSegment { value = 3.0; title = "Taxi"; fillStyle = RadialGradientBrushStyle(0xffe97064, 0xffe97064) }
pieSegment { value = 23.2; title = "Car"; fillStyle = RadialGradientBrushStyle(0xff47bde6, 0xff47bde6) }
pieSegment { value = 3.1; title = "Motorcycle"; fillStyle = RadialGradientBrushStyle(0xff47bde6, 0xff47bde6) }
pieSegment { value = 5.3; title = "Other"; fillStyle = RadialGradientBrushStyle(0xff47bde6, 0xff47bde6) }
}
}
binding.pieChart.run {
renderableSeries {
rSeries(pieSeries)
rSeries(donutSeries)
}
chartModifiers {
pieChartLegendModifier(binding.pieChartLegend) {
setSourceSeries(pieSeries)
setShowCheckboxes(false)
}
pieChartTooltipModifier()
}
}
pieSeries.animate(Constant.ANIMATION_DURATION)
donutSeries.animate(Constant.ANIMATION_DURATION)
}
}Java: MultiplePieDonutChartFragment.java
View source code//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// MultiplePieDonutChartFragment.java is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************
package com.scichart.examples.fragments.examples2d.createGaugeCharts;
import android.view.LayoutInflater;
import androidx.annotation.NonNull;
import com.scichart.charting.modifiers.PieChartTooltipModifier;
import com.scichart.charting.visuals.SciPieChartSurface;
import com.scichart.charting.visuals.renderableSeries.IPieRenderableSeries;
import com.scichart.examples.databinding.ExampleSinglePieChartWithLegendFragmentBinding;
import com.scichart.examples.fragments.base.ExampleBaseFragment;
import com.scichart.examples.utils.Constant;
import java.util.Collections;
public class MultiplePieDonutChartFragment extends ExampleBaseFragment<ExampleSinglePieChartWithLegendFragmentBinding> {
@NonNull
@Override
protected ExampleSinglePieChartWithLegendFragmentBinding inflateBinding(@NonNull LayoutInflater inflater) {
return ExampleSinglePieChartWithLegendFragmentBinding.inflate(inflater);
}
@Override
protected void initExample(ExampleSinglePieChartWithLegendFragmentBinding binding) {
final IPieRenderableSeries pieSeries = sciChartBuilder.newPieSeries().withSeriesName("HowPeopleTravel").withSegments(
sciChartBuilder.newPieSegment().withValue(34).withTitle("Ecologic").withRadialGradientColors(0xff68bcae, 0xff68bcae).build(),
sciChartBuilder.newPieSegment().withValue(34.4).withTitle("Municipal").withRadialGradientColors(0xffe97064, 0xffe97064).build(),
sciChartBuilder.newPieSegment().withValue(31.6).withTitle("Personal").withRadialGradientColors(0xff47bde6, 0xff47bde6).build()
).build();
final IPieRenderableSeries donutSeries = sciChartBuilder.newDonutSeries().withSeriesName("DetailedGroup").withSegments(
sciChartBuilder.newPieSegment().withValue(28.8).withTitle("Walking").withRadialGradientColors(0xff68bcae, 0xff68bcae).build(),
sciChartBuilder.newPieSegment().withValue(5.2).withTitle("Bicycle").withRadialGradientColors(0xff68bcae, 0xff68bcae).build(),
sciChartBuilder.newPieSegment().withValue(12.3).withTitle("Metro").withRadialGradientColors(0xffe97064, 0xffe97064).build(),
sciChartBuilder.newPieSegment().withValue(3.5).withTitle("Tram").withRadialGradientColors(0xffe97064, 0xffe97064).build(),
sciChartBuilder.newPieSegment().withValue(5.9).withTitle("Rail").withRadialGradientColors(0xffe97064, 0xffe97064).build(),
sciChartBuilder.newPieSegment().withValue(9.7).withTitle("Bus").withRadialGradientColors(0xffe97064, 0xffe97064).build(),
sciChartBuilder.newPieSegment().withValue(3.0).withTitle("Taxi").withRadialGradientColors(0xffe97064, 0xffe97064).build(),
sciChartBuilder.newPieSegment().withValue(23.2).withTitle("Car").withRadialGradientColors(0xff47bde6, 0xff47bde6).build(),
sciChartBuilder.newPieSegment().withValue(3.1).withTitle("Motorcycle").withRadialGradientColors(0xff47bde6, 0xff47bde6).build(),
sciChartBuilder.newPieSegment().withValue(5.3).withTitle("Other").withRadialGradientColors(0xff47bde6, 0xff47bde6).build()
).build();
final SciPieChartSurface pieChart = binding.pieChart;
Collections.addAll(pieChart.getRenderableSeries(), pieSeries, donutSeries);
Collections.addAll(pieChart.getChartModifiers(), sciChartBuilder.newLegendModifier(binding.pieChartLegend).withShowCheckBoxes(false).withSourceSeries(pieSeries).build(), new PieChartTooltipModifier());
pieSeries.animate(Constant.ANIMATION_DURATION);
donutSeries.animate(Constant.ANIMATION_DURATION);
}
}Back to Android Chart Examples


