abtsoftware / scichart.android.examples Goto Github PK
View Code? Open in Web Editor NEWExamples, Tutorials for SciChart Android: Realtime Android Chart Controls
Home Page: www.scichart.com
License: MIT License
Examples, Tutorials for SciChart Android: Realtime Android Chart Controls
Home Page: www.scichart.com
License: MIT License
I want to show real time data in chart, the real time data will come from api.
present I have made a chart which shows static data, there are 2 line graph in one chart
I have implemented TA-Lib library for more Indicators in Sci-chart
I've tried many ways to display realtime data in chart it is not working, So I just want to know how to update chart every time when I get a data from api
So please help me how to implement the real time data in Sci-Chart
CODE
public class CreateMultiPaneStockChartsFragment extends ExampleBaseFragment {
private static final String RSI = "RSI";
@BindView(R.id.rsiChart)
SciChartSurface rsiChart;
private final SciChartVerticalGroup verticalGroup = new SciChartVerticalGroup();
private final DoubleRange sharedXRange = new DoubleRange();
@Override
protected int getLayoutId() {
return R.layout.example_multipane_stock_charts_fragment;
}
@Override
public boolean showDefaultModifiersInToolbar() {
return false;
}
@Override
protected void initExample() {
final PriceSeries priceData = DataManager.getInstance().getPriceDataEurUsd(getActivity()); //get data form .csv file
final RsiPaneModel rsiPaneModel = new RsiPaneModel(sciChartBuilder, priceData);
initChart(rsiChart, rsiPaneModel, false);
}
private static class RsiPaneModel extends BasePaneModel {
public RsiPaneModel(SciChartBuilder builder, PriceSeries prices) {
super(builder, RSI, "0.00", false);
final MovingAverage.MacdPoints macdPoints = MovingAverage.macd(prices.getCloseData(), 12, 25, 9); //From Moving Average Class
final XyDataSeries<Date, Double> smaSeries = builder.newXyDataSeries(Date.class, Double.class).withSeriesName("SMA").build(); //ArrayList<String> al=new ArrayList<String>(); ..Java List Interface
final XyDataSeries<Date, Double> macdSeries = builder.newXyDataSeries(Date.class, Double.class).withSeriesName("MACD").build(); //ArrayList<String> al=new ArrayList<String>(); ..Java List Interface
appendSmaData(prices, smaSeries,builder);
appendMacdData(prices, macdSeries,builder, macdPoints);
Collections.addAll(annotations,
builder.newAxisMarkerAnnotation().withY1(macdSeries.getYValues().get(macdSeries.getCount() - 1)).withYAxisId("MACD").build(),
builder.newAxisMarkerAnnotation().withY1(smaSeries.getYValues().get(smaSeries.getCount() - 1)).withYAxisId("sma").build());
}
private void appendSmaData(PriceSeries prices, XyDataSeries<Date, Double> smaSeries,SciChartBuilder builder) {
final Core core = new Core();
final MInteger begin = new MInteger();
final MInteger length = new MInteger();
final List<Double> closeData = prices.getCloseData();
// copy data from List<Double> to double[] array because it's required by TA-Lib
final int size = closeData.size();
final double[] closeDataArray = new double[size];
final double[] rsiData = new double[size];
for (int i = 0; i < size; i++) {
closeDataArray[i] = closeData.get(i);
}
// calculate RSI
final int period = 14;
final RetCode retCode = core.sma(0, closeDataArray.length - 1, closeDataArray, period, begin, length, rsiData);
if(retCode == RetCode.Success) {
final List<Date> dateData = prices.getDateData();
final int beginIndex = begin.value;
final int endIndex = beginIndex + length.value;
// append NaN values for points which we can't calculate RSI
for (int i = 0; i < beginIndex; i++) {
smaSeries.append(dateData.get(i), Double.NaN);
}
// append calculated RSI data
for (int i = beginIndex; i < endIndex; i++) {
smaSeries.append(dateData.get(i), rsiData[i - beginIndex]);
}
}
addRenderableSeries(builder.newLineSeries().withDataSeries(smaSeries).withStrokeStyle(Color.GREEN, 5f).withYAxisId(RSI).build()); // color rsi
}
private void appendMacdData(PriceSeries prices, XyDataSeries<Date, Double> macdSeries,SciChartBuilder builder, MovingAverage.MacdPoints macdPoints) {
final Core core = new Core();
final MInteger begin = new MInteger();
final MInteger length = new MInteger();
final List<Double> closeData = prices.getCloseData();
// copy data from List<Double> to double[] array because it's required by TA-Lib
final int size = closeData.size();
final double[] closeDataArray = new double[size];
final double[] rsiData = new double[size];
for (int i = 0; i < size; i++) {
closeDataArray[i] = closeData.get(i);
}
// calculate RSI
Double [] macdValues = macdPoints.macdValues.toArray(new Double[macdPoints.macdValues.size()]);
Double [] signalValues = macdPoints.signalValues.toArray(new Double[macdPoints.signalValues.size()]);
double[] dSignalValues = new double[signalValues.length];
double[] dMacdValues = new double[macdValues.length];
for (int i=0;i<signalValues.length;i++){
dSignalValues[i]=Double.valueOf(signalValues[i]);
}
for (int i=0;i<macdValues.length;i++){
dMacdValues[i]=Double.valueOf(macdValues[i]);
}
final RetCode retCode = core.macd(0, closeDataArray.length - 1, closeDataArray, 12, 25, 9, begin, length, rsiData,dMacdValues, dMacdValues);
if(retCode == RetCode.Success) {
final List<Date> dateData = prices.getDateData();
final int beginIndex = begin.value;
final int endIndex = beginIndex + length.value;
// append NaN values for points which we can't calculate RSI
for (int i = 0; i < beginIndex; i++) {
macdSeries.append(dateData.get(i), Double.NaN);
}
// append calculated RSI data
for (int i = beginIndex; i < endIndex; i++) {
macdSeries.append(dateData.get(i), rsiData[i - beginIndex]);
}
addRenderableSeries(builder.newLineSeries().withDataSeries(macdSeries).withStrokeStyle(R.color.dashboard_chart_red_series_0, 1.5f).withYAxisId(RSI).build()); // color rsi
}
}
}
private void initChart(SciChartSurface surface, BasePaneModel model, boolean isMainPane) {
final CategoryDateAxis xAxis = sciChartBuilder.newCategoryDateAxis() //set x-axis Date data with properties
.withVisibility(isMainPane ? View.VISIBLE : View.GONE)
.withVisibleRange(sharedXRange)
.withGrowBy(0, 0.05)
.build();
surface.getXAxes().add(xAxis);
surface.getYAxes().add(model.yAxis); //Take from BasePaneModel
surface.setBackgroundColor (Color.WHITE); //Background color
surface.getRenderableSeries().addAll(model.renderableSeries);
surface.getChartModifiers().add(sciChartBuilder //ChartModifiers are the classes which can be added to a chart to give it a certain behaviour. For instance, all zooming, panning operations, tooltips, legends and even selection of points or lines are handled by ChartModifierBase derived classes in the SciChart codebase.
.newModifierGroup()
.withXAxisDragModifier().withReceiveHandledEvents(true).withDragMode(AxisDragModifierBase.AxisDragMode.Pan).withClipModex(ClipMode.StretchAtExtents).build()
.withPinchZoomModifier().withReceiveHandledEvents(true).withXyDirection(Direction2D.XDirection).build()
.withZoomPanModifier().withReceiveHandledEvents(true).build()
.withZoomExtentsModifier().withReceiveHandledEvents(true).build()
.withLegendModifier().withShowCheckBoxes(false).build()
.build());
xAxis.setDrawMajorGridLines(true);
xAxis.setDrawMinorGridLines(false);
xAxis.setDrawMajorBands(false);
model.yAxis.setDrawMajorGridLines(true);
model.yAxis.setDrawMinorGridLines(false);
model.yAxis.setDrawMajorBands(false);
model.yAxis.setGrowBy(new DoubleRange(0.5d, 0.5d));
surface.setAnnotations(model.annotations);
verticalGroup.addSurfaceToGroup(surface);
}
private abstract static class BasePaneModel {
public final RenderableSeriesCollection renderableSeries;
public final AnnotationCollection annotations;
public final NumericAxis yAxis;
public final String title;
protected BasePaneModel(SciChartBuilder builder, String title, String yAxisTextFormatting, boolean isFirstPane) {
this.title = title;
this.renderableSeries = new RenderableSeriesCollection();
this.annotations = new AnnotationCollection();
this.yAxis = builder.newNumericAxis () //Set Y Axis Numeric Axis
.withAxisId(title)
.withTextFormatting(yAxisTextFormatting)
.withAutoRangeMode(AutoRange.Always) //Adjust screen size horizontally
.withDrawMinorGridLines(false)
.withMinorsPerMajor(isFirstPane ? 4 : 2)
.withMaxAutoTicks(isFirstPane ? 8 : 4)
.withGrowBy(isFirstPane ? new DoubleRange(0.5d, 0.5d) : new DoubleRange(0.1d, 0.1d))
.build();
}
final void addRenderableSeries(BaseRenderableSeries renderableSeries) {
renderableSeries.setClipToBounds(true);
this.renderableSeries.add(renderableSeries);
}
}
}
Static Output
https://i.imgur.com/wXjBtDD.jpg
Hello, I'm working on an android application and I want to use an array of strings on xAxis instead of Date, is there a way I can provide just simply an array of strings and it should display as I needed?
Thanks
Regards
SciChartSurface has no XAxes. Please ensure SciChartSurface.XAxis is set, or SciChartSurface.XAxes has at least one axis
the reason?
I want to use TA-Lib in sciChart of my android app..
I had a word with the tech support of sciChart about TA-Lib implementation in SciChart..
So the Tech Support provide this project link.. I have check it & I have not got any TA-Lib dependency or
TA-Lib jar file implemented in this project..
This project include indicator like RSI, MACD and Volume so can I known what is the dependency or jar file of this indicators ..
Please guide me..
A terrible showcase, a mishmash of rxjava and binding. Make an illustrative example please.
Hello
I am trying to set fix labels in X axis so user doesn't require to zoom in to see all the labels, actually I have to show all the hours of the day like 01 to 24hrs in x axis. Any idea how can I achieve this?
Thanks
Hey, I am unable to find any example related to Android Kotlin/Java which demonstrate how to rotate a xAxis Lable to 90degree, only documentation is availblable but these are not useful, also most of the solutions are available for WPF forms.
I would really appreciate if you please provide a hands-on code to how to rotate a xaxis label.
Thanks
I want to change background color black to white.
after update react-native to 0.64.1 - get crash on tap chart
do you have any proguard issue when upgrading to 8.2?
Hello. We use your library to draw graphs and encountered the same problem. On devices with the ARMv8-A hardware platform (for example, Samsung Galaxy J2, Samsung Galaxy J4, Samsung Galaxy A03, Huawei ART-L29), our application crashes when the license key of your library is initialized.
Tell me if your library works with the ARMv8-A hardware platform and what we should do to avoid this problem.
Error log:
Fatal Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com....-LO5tYELuNVffVTjoL1f3CA==/base.apk"],nativeLibraryDirectories=[/data/app/com....-LO5tYELuNVffVTjoL1f3CA==/lib/arm64, /system/lib64, /hw_product/lib64, /system/product/lib64]]] couldn't find "libcore.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1668)
at com.scichart.core.utility.NativeLibraryHelper.tryLoadLibrary(SourceFile:3)
at com.scichart.core.utility.NativeLibraryHelper.tryLoadCoreLibrary(NativeLibraryHelper.java:1)
at com.scichart.core.licensing.Credentials.<clinit>(SourceFile:1)
at com.scichart.charting.visuals.SciChartSurface.setRuntimeLicenseKey(SourceFile:1)
at com.scichart.charting.visuals.SciChartSurface.setRuntimeLicenseKeyFromResource(SciChartSurface.java:7)
Library call code:
SciChartSurface.setRuntimeLicenseKeyFromResource(applicationContext, R.raw.scichart_release)
Library version:
4.2.0.4631
I have tried these examples without any modifications on two different devices:
The 3d charts crash on the first device, but work on the second device. The 2d charts work on both devices. I get the same issue with the example app in the Play Store.
Below is the crash dump:
ActivityManager system_server I Start proc 24986:com.samsung.android.oneconnect:Core/u0a307 for service {com.samsung.android.oneconnect/com.samsung.android.pluginplatform.service.PluginPlatformService}
libtwister com.scichart.examples I ==============================================================
libtwister com.scichart.examples I Starting Twister engine session at Mon Jul 8 21:06:05 2024
libtwister com.scichart.examples I ==============================================================
libtwister com.scichart.examples I GLES2 SubSystem successfully Initialized
libtwister com.scichart.examples I OpenGL Version = OpenGL ES 3.2 ANGLE git hash: 420895f80df0
libtwister com.scichart.examples I OpenGL Vendor = Samsung Electronics Co., Ltd.
libc com.scichart.examples A FORTIFY: vsprintf: prevented 4499-byte write into 4096-byte buffer
libc com.scichart.examples A Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 24985 (GLThread 10103), pid 17284 (ichart.examples)
hello ,I find a problem,use boxAnnotation,Anyway, change the drawing order ,boxAnnotation all on the top level,Is there any way to make it draw at the lower level, that is, first
Hi guys, did you test your demo app? =)
When I tested your demo I've got a lot of exceptions in logcat and runtime crashes. Is your SDK written like demos?
For example, what is going after setting values to views from not UI thread? =) https://github.com/ABTSoftware/SciChart.Android.Examples/blob/master/v2.x/Examples/app/src/main/java/com/scichart/examples/fragments/PerformanceDemoFragment.java#L258
This looks tastier on the "RealTime Ghost Traces": http://imgur.com/a/KDEyR
I used box annotation like pic
in a boxAnnotation I used
.withIsEditable(true)
.withPosition(1,-2, 0, 2)
.withBackgroundDrawableId(R.drawable.example_box_annotation_background_4)
.withResizingGrip(customIResizingGrip)
.withAnnotationDragListener(customIAnnotationSelectionDrawable)
.withResizeDirections(Direction2D.XDirection)
.withDragDirections(Direction2D.XDirection)
.build();
and i made a 2 box like pic
i use box for drag one side to make a box big or small
the first box which is left doesn’t move anywhere.
it just can only drag that i want
but the second box, the box moves when i drag after first touch
the left box never moves on but right box moves first drags
just move sometimes
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2017. All rights reserved.
//
// Web: http://www.scichart.com
// Support: [email protected]
// Sales: [email protected]
//
// AnnotationsAreEasyFragment.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.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com.scichart.charting.Direction2D;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.annotations.BoxAnnotation;
import com.scichart.charting.visuals.annotations.HorizontalAnchorPoint;
import com.scichart.charting.visuals.annotations.IAnnotation;
import com.scichart.charting.visuals.annotations.IResizingGrip;
import com.scichart.charting.visuals.annotations.OnAnnotationDragListener;
import com.scichart.charting.visuals.annotations.VerticalAnchorPoint;
import com.scichart.charting.visuals.axes.IAxis;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.examples.R;
import com.scichart.examples.fragments.base.ExampleBaseFragment;
import java.util.Collections;
import butterknife.BindView;
public class AnnotationsAreEasyFragment extends ExampleBaseFragment {
@BindView(R.id.chart)
SciChartSurface surface;
@Override
public boolean showDefaultModifiersInToolbar() {
return false;
}
@Override
protected int getLayoutId() {
return R.layout.example_single_chart_fragment;
}
@Override
protected void initExample() {
Paint paint = new Paint();
paint.setColor(Color.RED);
Canvas canvas = new Canvas();
canvas.drawRect(100, 100, 100, 100, paint);
CustomIResizingGrip customIResizingGrip = new CustomIResizingGrip();
CustomLeftBoxAnnotationDragListener customLeftBoxAnnotationDragListener = new CustomLeftBoxAnnotationDragListener();
CustomRightBoxAnnotationDragListener customRightBoxAnnotationDragListener = new CustomRightBoxAnnotationDragListener();
customIResizingGrip.onDraw(canvas, 10, 20);
final BoxAnnotation boxAnnotation = sciChartBuilder.newBoxAnnotation()
.withIsEditable(true)
.withPosition(7d, 2d, 9d, 4d)
.withBackgroundDrawableId(R.drawable.example_box_annotation_background_4)
.withResizingGrip(customIResizingGrip)
.withAnnotationDragListener(customLeftBoxAnnotationDragListener)
.withDragDirections(Direction2D.XDirection)
.withResizeDirections(Direction2D.XDirection)
.build();
final BoxAnnotation boxAnnotation2 = sciChartBuilder.newBoxAnnotation()
.withIsEditable(true)
.withPosition(4d,4d, 2d,2d)
.withBackgroundDrawableId(R.drawable.example_box_annotation_background_4)
.withResizingGrip(customIResizingGrip)
.withAnnotationDragListener(customRightBoxAnnotationDragListener)
.withDragDirections(Direction2D.XDirection)
.withResizeDirections(Direction2D.XDirection)
.build();
UpdateSuspender.using(surface, new Runnable() {
@Override
public void run() {
final IAxis xAxis = sciChartBuilder.newNumericAxis()
.withVisibleRange(0d, 10d)
.withGrowBy(0.1d, 0.1d)
.withTextFormatting("0.0#")
.build();
final IAxis yAxis = sciChartBuilder.newNumericAxis()
.withVisibleRange(0d, 10d)
.withGrowBy(0.1d, 0.1d)
.withTextFormatting("0.0#")
.build();
Collections.addAll(surface.getXAxes(), xAxis);
Collections.addAll(surface.getYAxes(), yAxis);
Collections.addAll(surface.getAnnotations(), boxAnnotation, boxAnnotation2);
Collections.addAll(surface.getAnnotations(),
sciChartBuilder.newTextAnnotation()
.withX1(5d)
.withY1(8d)
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Center)
.withVerticalAnchorPoint(VerticalAnchorPoint.Bottom)
.withText("Anchor Center (X1, Y1)")
.build(),
sciChartBuilder.newTextAnnotation()
.withX1(5d)
.withY1(8d)
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Right)
.withVerticalAnchorPoint(VerticalAnchorPoint.Top)
.withText("Anchor Right")
.build(),
sciChartBuilder.newTextAnnotation()
.withX1(5d)
.withY1(8d)
.withHorizontalAnchorPoint(HorizontalAnchorPoint.Left)
.withVerticalAnchorPoint(VerticalAnchorPoint.Top)
.withText("or Anchor Left")
.build());
surface.getChartModifiers().add(sciChartBuilder.newModifierGroupWithDefaultModifiers().build());
}
});
}
public static class CustomView1 extends View {
private final int FILL_COLOR = Color.parseColor("#571CB61C");
private final int STROKE_COLOR = Color.parseColor("#FF00B400");
private final Path path = new Path();
private final Paint paintFill = new Paint();
private final Paint paintStroke = new Paint();
public CustomView1(Context context) {
super(context);
init();
}
public CustomView1(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
paintFill.setStyle(Paint.Style.FILL);
paintFill.setColor(FILL_COLOR);
paintStroke.setStyle(Paint.Style.STROKE);
paintStroke.setColor(STROKE_COLOR);
path.moveTo(0, 15);
path.lineTo(15, 0);
path.lineTo(30, 15);
path.lineTo(20, 15);
path.lineTo(20, 30);
path.lineTo(10, 30);
path.lineTo(10, 15);
path.lineTo(0, 15);
setMinimumHeight(50);
setMinimumWidth(50);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPath(path, paintFill);
canvas.drawPath(path, paintStroke);
}
}
public static class CustomView2 extends View {
private final int FILL_COLOR = Color.parseColor("#57B22020");
private final int STROKE_COLOR = Color.parseColor("#FF990000");
private final Path path = new Path();
private final Paint paintFill = new Paint();
private final Paint paintStroke = new Paint();
public CustomView2(Context context) {
super(context);
paintFill.setStyle(Paint.Style.FILL);
paintFill.setColor(FILL_COLOR);
paintStroke.setStyle(Paint.Style.STROKE);
paintStroke.setColor(STROKE_COLOR);
path.moveTo(0, 15);
path.lineTo(10, 15);
path.lineTo(10, 0);
path.lineTo(20, 0);
path.lineTo(20, 15);
path.lineTo(30, 15);
path.lineTo(15, 30);
path.lineTo(0, 15);
setMinimumHeight(50);
setMinimumWidth(50);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPath(path, paintFill);
canvas.drawPath(path, paintStroke);
}
}
public static class CustomLeftBoxAnnotationDragListener implements OnAnnotationDragListener {
@Override
public void onDragStarted(IAnnotation iAnnotation) {
}
@Override
public void onDragEnded(IAnnotation iAnnotation) {
iAnnotation.setSelected(false);
Log.i("Left", String.valueOf(iAnnotation.getX1()));
}
@Override
public void onDragDelta(IAnnotation iAnnotation, float v, float v1) {
}
}
public static class CustomRightBoxAnnotationDragListener implements OnAnnotationDragListener {
@Override
public void onDragStarted(IAnnotation iAnnotation) {
}
@Override
public void onDragEnded(IAnnotation iAnnotation) {
iAnnotation.setSelected(false);
Log.i("Right", String.valueOf(iAnnotation.getX1()));
}
@Override
public void onDragDelta(IAnnotation iAnnotation, float v, float v1) {
}
}
public static class CustomIResizingGrip implements IResizingGrip {
@Override
public void onDraw(Canvas canvas, float v, float v1) {
}
@Override
public boolean isHit(float v, float v1, float v2, float v3) {
return true;
}
}
有没有能设置MajorTicks方向的方向
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.