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.
Demonstrates the use of the RolloverModifier, part of the ChartModifier API for getting information about Renderable Series and its displaying on tooltips.
Tip!
The SeriesInfo acts as a data-source for the data-point, and each SeriesInfo derived type contains:
– The X,Y values of the series under the cursor.
– The series color.
– The series name.
It can be extended or replaced by a custom SeriesInfo by creating your own SeriesInfoProvider for a Renderable Series.
The full source code for the Android Chart with Rollover Tooltips 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: UsingRolloverModifierTooltipsFragment.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
//
// UsingRolloverModifierTooltipsFragment.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.tooltipsAndHitTest.kt
import android.view.View
import android.view.animation.DecelerateInterpolator
import android.widget.AdapterView
import android.widget.CompoundButton
import android.widget.Spinner
import com.scichart.charting.modifiers.RolloverModifier
import com.scichart.charting.modifiers.SourceMode
import com.scichart.charting.visuals.SciChartSurface
import com.scichart.data.model.DoubleRange
import com.scichart.drawing.utility.ColorUtil
import com.scichart.examples.R
import com.scichart.examples.components.SpinnerStringAdapter
import com.scichart.examples.fragments.base.ExampleSingleChartBaseFragment
import com.scichart.examples.utils.Constant
import com.scichart.examples.utils.EnumUtils
import com.scichart.examples.utils.ItemSelectedListenerBase
import com.scichart.examples.utils.ViewSettingsUtil
import com.scichart.examples.utils.interpolator.DefaultInterpolator
import com.scichart.examples.utils.scichartExtensions.*
import com.scichart.examples.utils.widgetgeneration.ImageViewWidget
import com.scichart.examples.utils.widgetgeneration.Widget
import java.util.ArrayList
import kotlin.math.sin
class UsingRolloverModifierTooltipsFragment: ExampleSingleChartBaseFragment() {
private val sourceModeValues = listOf(*SourceMode.values())
private lateinit var rolloverModifier: RolloverModifier
private var selectedSourceMode = 1
private var showTooltip = true
private var showAxisLabels = true
private var drawVerticalLine = true
override fun initExample(surface: SciChartSurface) {
val ds1 = XyDataSeries<Int, Double>("SineWave A")
val ds2 = XyDataSeries<Int, Double>("SineWave B")
val ds3 = XyDataSeries<Int, Double>("SineWave C")
val count = 100.0
val k = 2 * Math.PI / 30.0
for (i in 0 until count.toInt()) {
val phi = k * i
ds1.append(i, (1.0 + i / count) * sin(phi))
ds2.append(i, (0.5 + i / count) * sin(phi))
ds3.append(i, i / count * sin(phi))
}
surface.suspendUpdates {
xAxes { numericAxis() }
yAxes { numericAxis { growBy = DoubleRange(0.2, 0.2) } }
renderableSeries {
fastLineRenderableSeries {
dataSeries = ds1
strokeStyle = SolidPenStyle(0xFF47bde6, 2f)
ellipsePointMarker { setSize(7); fillStyle = SolidBrushStyle(ColorUtil.Lavender) }
sweepAnimation {
interpolator = DefaultInterpolator.getInterpolator()
duration = Constant.ANIMATION_DURATION
startDelay = Constant.ANIMATION_START_DELAY
}
}
fastLineRenderableSeries {
dataSeries = ds2
strokeStyle = SolidPenStyle(0xFFae418d, 2f)
ellipsePointMarker { setSize(7); fillStyle = SolidBrushStyle(ColorUtil.Lavender) }
sweepAnimation {
interpolator = DefaultInterpolator.getInterpolator()
duration = Constant.ANIMATION_DURATION
startDelay = Constant.ANIMATION_START_DELAY
}
}
fastLineRenderableSeries {
dataSeries = ds3
strokeStyle = SolidPenStyle(0xFF68bcae, 2f)
sweepAnimation {
interpolator = DefaultInterpolator.getInterpolator()
duration = Constant.ANIMATION_DURATION
startDelay = Constant.ANIMATION_START_DELAY
}
}
}
chartModifiers {
rolloverModifier {
showTooltip = this@UsingRolloverModifierTooltipsFragment.showTooltip
showAxisLabels = this@UsingRolloverModifierTooltipsFragment.showAxisLabels
drawVerticalLine = this@UsingRolloverModifierTooltipsFragment.drawVerticalLine
rolloverModifier = this
}
}
}
}
override fun getToolbarItems(): List<Widget> = ArrayList<Widget>().apply {
add(ImageViewWidget.Builder().setId(R.drawable.example_toolbar_settings).setListener { openSettingsDialog() }.build())
}
private fun openSettingsDialog() {
val dialog = ViewSettingsUtil.createSettingsPopup(activity, R.layout.example_using_rollover_modofier_tooltips_popup_layout)
val context = dialog.context
dialog.findViewById<Spinner>(R.id.legend_source_spinner_rollover).run {
adapter = SpinnerStringAdapter(context, EnumUtils.getEnumValuesArray(SourceMode::class.java))
setSelection(selectedSourceMode)
onItemSelectedListener = object : ItemSelectedListenerBase() {
override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
selectedSourceMode = position
rolloverModifier.sourceMode = sourceModeValues[selectedSourceMode]
}
}
}
ViewSettingsUtil.setUpSwitchCompat(dialog, R.id.show_tooltips_checkbox, showTooltip) { _: CompoundButton?, isChecked: Boolean ->
showTooltip = isChecked
rolloverModifier.showTooltip = showTooltip
}
ViewSettingsUtil.setUpSwitchCompat(dialog, R.id.show_axis_labels_checkbox, showAxisLabels) { _: CompoundButton?, isChecked: Boolean ->
showAxisLabels = isChecked
rolloverModifier.showAxisLabels = showAxisLabels
}
ViewSettingsUtil.setUpSwitchCompat(dialog, R.id.draw_vertical_line_checkbox, drawVerticalLine) { _: CompoundButton?, isChecked: Boolean ->
drawVerticalLine = isChecked
rolloverModifier.drawVerticalLine = drawVerticalLine
}
dialog.show()
}
}Java: UsingRolloverModifierTooltipsFragment.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
//
// UsingRolloverModifierTooltipsFragment.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.tooltipsAndHitTest;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.Spinner;
import com.scichart.charting.model.dataSeries.XyDataSeries;
import com.scichart.charting.modifiers.RolloverModifier;
import com.scichart.charting.modifiers.SourceMode;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.axes.IAxis;
import com.scichart.charting.visuals.pointmarkers.EllipsePointMarker;
import com.scichart.charting.visuals.renderableSeries.FastLineRenderableSeries;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.data.model.DoubleRange;
import com.scichart.drawing.utility.ColorUtil;
import com.scichart.examples.R;
import com.scichart.examples.components.SpinnerStringAdapter;
import com.scichart.examples.fragments.base.ExampleSingleChartBaseFragment;
import com.scichart.examples.utils.Constant;
import com.scichart.examples.utils.EnumUtils;
import com.scichart.examples.utils.ItemSelectedListenerBase;
import com.scichart.examples.utils.ViewSettingsUtil;
import com.scichart.examples.utils.interpolator.DefaultInterpolator;
import com.scichart.examples.utils.widgetgeneration.ImageViewWidget;
import com.scichart.examples.utils.widgetgeneration.Widget;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import androidx.annotation.NonNull;
public class UsingRolloverModifierTooltipsFragment extends ExampleSingleChartBaseFragment {
private static final List<SourceMode> sourceModeValues = unmodifiableList(asList(SourceMode.values()));
private RolloverModifier rolloverModifier;
private int selectedSourceMode = 1;
private boolean showTooltip = true;
private boolean showAxisLabels = true;
private boolean drawVerticalLine = true;
@Override
protected void initExample(@NonNull SciChartSurface surface) {
final IAxis xAxis = sciChartBuilder.newNumericAxis().build();
final IAxis yAxis = sciChartBuilder.newNumericAxis().withGrowBy(new DoubleRange(0.2d, 0.2d)).build();
rolloverModifier = new RolloverModifier();
rolloverModifier.setShowTooltip(showTooltip);
rolloverModifier.setShowAxisLabels(showAxisLabels);
rolloverModifier.setDrawVerticalLine(drawVerticalLine);
final XyDataSeries<Integer, Double> ds1 = sciChartBuilder.newXyDataSeries(Integer.class, Double.class).withSeriesName("SineWave A").build();
final XyDataSeries<Integer, Double> ds2 = sciChartBuilder.newXyDataSeries(Integer.class, Double.class).withSeriesName("SineWave B").build();
final XyDataSeries<Integer, Double> ds3 = sciChartBuilder.newXyDataSeries(Integer.class, Double.class).withSeriesName("SineWave C").build();
double count = 100.0;
double k = 2 * Math.PI / 30.0;
for (int i = 0; i < (int) count; i++) {
double phi = k * i;
ds1.append(i, (1.0 + i / count) * Math.sin(phi));
ds2.append(i, (0.5 + i / count) * Math.sin(phi));
ds3.append(i, (i / count) * Math.sin(phi));
}
final FastLineRenderableSeries rs1 = sciChartBuilder.newLineSeries()
.withDataSeries(ds1)
.withStrokeStyle(0xFF47bde6, 2)
.withPointMarker(sciChartBuilder.newPointMarker(new EllipsePointMarker()).withSize(7, 7).withFill(ColorUtil.Lavender).build())
.build();
final FastLineRenderableSeries rs2 = sciChartBuilder.newLineSeries()
.withDataSeries(ds2)
.withStrokeStyle(0xFFae418d, 2)
.withPointMarker(sciChartBuilder.newPointMarker(new EllipsePointMarker()).withSize(7, 7).withFill(ColorUtil.Lavender).build())
.build();
final FastLineRenderableSeries rs3 = sciChartBuilder.newLineSeries()
.withDataSeries(ds3)
.withStrokeStyle(0xFF68bcae, 2, true)
.build();
UpdateSuspender.using(surface, () -> {
Collections.addAll(surface.getXAxes(), xAxis);
Collections.addAll(surface.getYAxes(), yAxis);
Collections.addAll(surface.getRenderableSeries(), rs1, rs2, rs3);
Collections.addAll(surface.getChartModifiers(), rolloverModifier);
sciChartBuilder.newAnimator(rs1).withSweepTransformation().withInterpolator(DefaultInterpolator.getInterpolator()).withDuration(Constant.ANIMATION_DURATION).withStartDelay(Constant.ANIMATION_START_DELAY).start();
sciChartBuilder.newAnimator(rs2).withSweepTransformation().withInterpolator(DefaultInterpolator.getInterpolator()).withDuration(Constant.ANIMATION_DURATION).withStartDelay(Constant.ANIMATION_START_DELAY).start();
sciChartBuilder.newAnimator(rs3).withSweepTransformation().withInterpolator(DefaultInterpolator.getInterpolator()).withDuration(Constant.ANIMATION_DURATION).withStartDelay(Constant.ANIMATION_START_DELAY).start();
});
}
@NonNull
@Override
public List<Widget> getToolbarItems() {
return new ArrayList<Widget>() {{
add(new ImageViewWidget.Builder().setId(R.drawable.example_toolbar_settings).setListener(v -> openSettingsDialog()).build());
}};
}
private void openSettingsDialog() {
final Dialog dialog = ViewSettingsUtil.createSettingsPopup(getActivity(), R.layout.example_using_rollover_modofier_tooltips_popup_layout);
Context context = dialog.getContext();
final SpinnerStringAdapter legendSourceAdapter = new SpinnerStringAdapter(context, EnumUtils.getEnumValuesArray(SourceMode.class));
final Spinner legendSourceSpinner = (Spinner) dialog.findViewById(R.id.legend_source_spinner_rollover);
legendSourceSpinner.setAdapter(legendSourceAdapter);
legendSourceSpinner.setSelection(selectedSourceMode);
legendSourceSpinner.setOnItemSelectedListener(new ItemSelectedListenerBase() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedSourceMode = position;
rolloverModifier.setSourceMode(sourceModeValues.get(selectedSourceMode));
}
});
ViewSettingsUtil.setUpSwitchCompat(dialog, R.id.show_tooltips_checkbox, showTooltip, (buttonView, isChecked) -> {
showTooltip = isChecked;
rolloverModifier.setShowTooltip(showTooltip);
});
ViewSettingsUtil.setUpSwitchCompat(dialog, R.id.show_axis_labels_checkbox, showAxisLabels, (buttonView, isChecked) -> {
showAxisLabels = isChecked;
rolloverModifier.setShowAxisLabels(showAxisLabels);
});
ViewSettingsUtil.setUpSwitchCompat(dialog, R.id.draw_vertical_line_checkbox, drawVerticalLine, (buttonView, isChecked) -> {
drawVerticalLine = isChecked;
rolloverModifier.setDrawVerticalLine(drawVerticalLine);
});
dialog.show();
}
}Back to Android Chart Examples


