Skip to content

Instantly share code, notes, and snippets.

@ngiyus

ngiyus/tes.java

Created Feb 8, 2021
Embed
What would you like to do?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// view binding
binding = ActivityDemoBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
//init scichart
binding.sciChartSurface.setTheme(R.style.SciChart_BerryBlue);
SciChartBuilder.init(this);
SciChartBuilder sciChartBuilder = SciChartBuilder.instance();
//init data generator
this.marketDataService = new MarketDataService(new Date(2000, 8, 1, 12, 0, 0), 10, 60);
PriceSeries priceSeries = marketDataService.getHistoricalData(150);
//init axis
final IAxis xAxis = sciChartBuilder.newCategoryDateAxis()
.withVisibleRange(xVisibleRange)
.withGrowBy(0.1d, 0.1d)
.build();
final IAxis yAxis = sciChartBuilder.newNumericAxis()
.withGrowBy(0.5, 0.5)
.withAutoRangeMode(AutoRange.Always).build();
//initt xaxis
xAxis.setDrawMinorGridLines(false);
xAxis.setDrawMajorBands(false);
xAxis.setDrawMinorTicks(false);
xAxis.setAutoTicks(false);
xAxis.setMajorDelta(10d);
xAxis.setMinorDelta(10d);
//initt yaxis
yAxis.setDrawMinorGridLines(false);
yAxis.setDrawMajorBands(false);
// yAxis.setCursorTextFormatting("' Harga : '###.###' '");
//init data series
dataSeries = new OhlcDataSeries<>(Date.class, Double.class);
dataSeries.setAcceptsUnsortedData(true);
dataSeries.append(priceSeries.getDateData(), priceSeries.getOpenData(), priceSeries.getHighData(), priceSeries.getLowData(), priceSeries.getCloseData());
//init renderable series candlestick
candleSeries = sciChartBuilder.newCandlestickSeries()
.withDataSeries(dataSeries)
.build();
ohlcSeries = sciChartBuilder.newOhlcSeries().withDataSeries(dataSeries).build();
lineSeries = sciChartBuilder.newLineSeries().withDataSeries(dataSeries).build();
// init annotation
topMarker1 = sciChartBuilder.newAxisMarkerAnnotation()
.withAnnotationSurface(AnnotationSurfaceEnum.YAxis)
.withBackgroundColor(0x99279B27)
.withIsEditable(false)
.build();
// lineAnnotation = new LineAnnotation(this);
// lineAnnotation.setStroke(new SolidPenStyle(Color.BLACK, true, 1, null));
// lineAnnotation.setIsEditable(false);
// lineAnnotation.setX1(130d);
//
// lineAnnotation.setX2(163.2d);
horizontalLine = sciChartBuilder.newHorizontalLineAnnotation()
.withStroke(1, ColorUtil.Orange)
.withHorizontalGravity(Gravity.RIGHT)
.withIsEditable(false)
.build();
//initt modifier
ZoomPanModifier zoomPanModifier = new ZoomPanModifier();
zoomPanModifier.setClipModeX(ClipMode.ClipAtExtents);
zoomPanModifier.setClipModeTargetX(ClipModeTarget.MaximumRange);
zoomPanModifier.setDirection(Direction2D.XDirection);
UpdateSuspender.using(binding.sciChartSurface, new Runnable() {
@Override
public void run() {
Collections.addAll(binding.sciChartSurface.getXAxes(), xAxis);
Collections.addAll(binding.sciChartSurface.getYAxes(), yAxis);
Collections.addAll(binding.sciChartSurface.getRenderableSeries(), lineSeries);
Collections.addAll(binding.sciChartSurface.getAnnotations(), topMarker1, horizontalLine);
Collections.addAll(binding.sciChartSurface.getChartModifiers(),
zoomPanModifier);
}
});
binding.include.button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Turun", Toast.LENGTH_SHORT).show();
}
});
binding.include.button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Naik", Toast.LENGTH_SHORT).show();
}
});
binding.include.button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//buka pilihan
ItemListDialogFragment fragment = new ItemListDialogFragment();
fragment.show(getSupportFragmentManager(), "pilihan");
}
});
xAxis.setVisibleRangeChangeListener(new VisibleRangeChangeListener() {
@Override
public void onVisibleRangeChanged(IAxisCore iAxisCore, IRange iRange, IRange iRange1, boolean b) {
//cek jika data harus ambil laod history
if (iAxisCore.getVisibleRange().getMinAsDouble() <= 0) {
Toast.makeText(getApplicationContext(), "Load More", Toast.LENGTH_SHORT).show();
}
}
});
//mulai price gen
marketDataService.subscribePriceUpdate(onNewPrice());
TradeChartAxisLabelProvider tradeChartAxisLabelProvider = (TradeChartAxisLabelProvider) binding.sciChartSurface.getXAxes().get(0).getLabelProvider();
binding.sciChartSurface.getXAxes().get(0).getLabelProvider()).transformDataToIndex(new Date()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment