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.
Showcases how to synchronize axis ranges across multiple charts by sharing IRange instances. Two SciChartSurfaces are created and arranged vertically. This example shows how to synchronize Zoom, Pan, Axis Scale operations.
Tip!
The charts are synchronized by setting shared instances of DoubleRange as X-Axis VisibleRange and Y-Axis VisibleRange for both charts.
The full source code for the Android Chart Sync Multiple Charts example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
<?xml version="1.0" encoding="utf-8"?>
<!--*************************************************************************-->
<!-- SCICHART® Copyright SciChart Ltd. 2011-2016. All rights reserved. -->
<!-- -->
<!-- Web: http://www.scichart.com -->
<!-- Support: support@scichart.com -->
<!-- Sales: sales@scichart.com -->
<!-- -->
<!-- example_sync_multiple_charts_fragment.xml 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. -->
<!--*************************************************************************-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:context=".fragments.SyncMultipleChartsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.scichart.charting.visuals.SciChartSurface
android:id="@+id/chart0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<com.scichart.charting.visuals.SciChartSurface
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2017. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SyncMultipleChartsFragment.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 android.view.animation.DecelerateInterpolator;
import com.scichart.charting.model.dataSeries.IDataSeries;
import com.scichart.charting.model.dataSeries.IXyDataSeries;
import com.scichart.charting.model.dataSeries.XyDataSeries;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.axes.IAxis;
import com.scichart.charting.visuals.renderableSeries.FastLineRenderableSeries;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.data.model.DoubleRange;
import com.scichart.data.model.IRange;
import com.scichart.drawing.utility.ColorUtil;
import com.scichart.examples.R;
import com.scichart.examples.fragments.base.ExampleBaseFragment;
import java.util.Collections;
import butterknife.BindView;
public class SyncMultipleChartsFragment extends ExampleBaseFragment {
private final static int POINTS_COUNT = 500;
private IRange sharedXRange = new DoubleRange(0d, 1d);
private IRange sharedYRange = new DoubleRange(0d, 1d);
@BindView(R.id.chart0)
SciChartSurface chart0;
@BindView(R.id.chart1)
SciChartSurface chart1;
@Override
public boolean showDefaultModifiersInToolbar() {
return false;
}
@Override
protected int getLayoutId() {
return R.layout.example_sync_multiple_charts_fragment;
}
@Override
protected void initExample() {
initChart(chart0);
initChart(chart1);
}
private void initChart(final SciChartSurface surface) {
final IAxis xAxis = sciChartBuilder.newNumericAxis().withGrowBy(0.1d, 0.1d).withVisibleRange(sharedXRange).build();
final IAxis yAxis = sciChartBuilder.newNumericAxis().withGrowBy(0.1d, 0.1d).withVisibleRange(sharedYRange).build();
final FastLineRenderableSeries line = sciChartBuilder.newLineSeries().withDataSeries(createDataSeries()).withStrokeStyle(ColorUtil.Green, 1f, true).build();
UpdateSuspender.using(surface, new Runnable() {
@Override
public void run() {
Collections.addAll(surface.getXAxes(), xAxis);
Collections.addAll(surface.getYAxes(), yAxis);
Collections.addAll(surface.getRenderableSeries(), line);
Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroup()
.withMotionEventsGroup("ModifiersSharedEventsGroup").withReceiveHandledEvents(true)
.withZoomExtentsModifier().build()
.withPinchZoomModifier().build()
.withRolloverModifier().withReceiveHandledEvents(true).build()
.withXAxisDragModifier().withReceiveHandledEvents(true).build()
.withYAxisDragModifier().withReceiveHandledEvents(true).build()
.build());
surface.zoomExtents();
sciChartBuilder.newAnimator(line).withSweepTransformation().withInterpolator(new DecelerateInterpolator()).withDuration(3000).withStartDelay(350).start();
}
});
}
private IDataSeries createDataSeries() {
IXyDataSeries<Double, Double> dataSeries = new XyDataSeries<>(Double.class, Double.class);
for (int i = 1; i < POINTS_COUNT; i++) {
dataSeries.append((double) i, POINTS_COUNT * Math.sin(i * Math.PI * 0.1) / i);
}
return dataSeries;
}
}