private void CreateMainPriceChart() { // Create an XAxis and YAxis for our chart var xAxis = new CategoryDateAxis(Activity) { BarTimeFrame = TimeSpan.FromMinutes(5).TotalSeconds, DrawMajorGridLines = false, GrowBy = new DoubleRange(0, 0.1) }; var yAxis = new NumericAxis(Activity) { AutoRange = AutoRange.Always }; // Create RenderableSeries to render the data var ohlcSeries = new FastOhlcRenderableSeries { DataSeries = _ohlcDataSeries, StrokeUpStyle = new SolidPenStyle(StrokeUpColor, StrokeThickness.ToDip(Activity)), StrokeDownStyle = new SolidPenStyle(StrokeDownColor, StrokeThickness.ToDip(Activity)), }; var movingAverage50Series = new FastLineRenderableSeries { DataSeries = _xyDataSeries, StrokeStyle = new SolidPenStyle(0xFFFF6600, 1.0f) }; // Create axis markers annotations to show the last values on real-time chart _smaAxisMarker = new AxisMarkerAnnotation(Activity) { Y1Value = 0d }; _smaAxisMarker.SetBackgroundColor(SmaSeriesColor.ToColor()); _ohlcAxisMarker = new AxisMarkerAnnotation(Activity) { Y1Value = 0d }; _ohlcAxisMarker.SetBackgroundColor(StrokeUpColor.ToColor()); // Populate the chart with Axis, RenderableSeries. The chart automatically updates when any property changes using (MainSurface.SuspendUpdates()) { MainSurface.XAxes.Add(xAxis); MainSurface.YAxes.Add(yAxis); MainSurface.RenderableSeries.Add(ohlcSeries); MainSurface.RenderableSeries.Add(movingAverage50Series); MainSurface.Annotations.Add(_ohlcAxisMarker); MainSurface.Annotations.Add(_smaAxisMarker); // Populate some pinch and touch interactions. Pinch to zoom, drag to pan and double-tap to zoom extents MainSurface.ChartModifiers = new ChartModifierCollection { new XAxisDragModifier(), new ZoomPanModifier { Direction = Direction2D.XDirection }.WithReceiveHandledEvents(true), new ZoomExtentsModifier(), new LegendModifier(Activity).WithOrientation(Orientation.Horizontal).WithPosition(GravityFlags.CenterHorizontal | GravityFlags.Bottom, 20).WithReceiveHandledEvents(true), }; } }
protected override void InitExample() { var xAxis = new NumericAxis(Activity) { VisibleRange = new DoubleRange(150d, 165d) }; var yAxis = new NumericAxis(Activity) { LabelProvider = new ThousandsLabelProvider(), GrowBy = new DoubleRange(0, 0.1), AutoRange = AutoRange.Always }; var dataManager = DataManager.Instance; var priceBars = dataManager.GetPriceDataIndu(); var mountainDataSeries = new XyDataSeries <double, double>() { SeriesName = "Mountain Series" }; var lineDataSeries = new XyDataSeries <double, double>() { SeriesName = "Line Series" }; var columnDataSeries = new XyDataSeries <double, double>() { SeriesName = "Column Series" }; var scatterDataSeries = new XyDataSeries <double, double>() { SeriesName = "Scatter Series" }; var candlestickDataSeries = new OhlcDataSeries <double, double>() { SeriesName = "Candlestick Series" }; var ohlcDataSeries = new OhlcDataSeries <double, double>() { SeriesName = "OHLC Series" }; var xValues = Enumerable.Range(0, priceBars.Count).Select(x => (double)x).ToArray(); mountainDataSeries.Append(xValues, priceBars.LowData.Select(x => x - 2000d)); lineDataSeries.Append(xValues, priceBars.CloseData.Select(x => x + 1000d)); ohlcDataSeries.Append(xValues, priceBars.OpenData, priceBars.HighData, priceBars.LowData, priceBars.CloseData); candlestickDataSeries.Append(xValues, priceBars.OpenData.Select(x => x - 1000d), priceBars.HighData.Select(x => x - 1000d), priceBars.LowData.Select(x => x - 1000d), priceBars.CloseData.Select(x => x - 1000d)); columnDataSeries.Append(xValues, priceBars.CloseData.Select(x => x - 3000d)); scatterDataSeries.Append(xValues, priceBars.OpenData.Select(x => x - 2500d)); var annotation = new BoxAnnotation(Activity) { X1Value = 152d, Y1Value = 0d, X2Value = 158d, Y2Value = 1d, Background = Activity.GetDrawableCompat(Resource.Drawable.example_box_annotation_background_1), IsEditable = true, CoordinateMode = AnnotationCoordinateMode.RelativeY }; annotation.SetOnAnnotationDragListener(new AnnotationDragListener()); var mountainSeries = new FastMountainRenderableSeries { DataSeries = mountainDataSeries, AreaStyle = new SolidBrushStyle(0x9787CEEB), StrokeStyle = new SolidPenStyle(Color.Magenta), PaletteProvider = new XyCustomPaletteProvider(Color.Red, annotation) }; var lineSeries = new FastLineRenderableSeries { DataSeries = lineDataSeries, StrokeStyle = new SolidPenStyle(Color.Blue), PointMarker = new EllipsePointMarker() { FillStyle = new SolidBrushStyle(Color.Red), StrokeStyle = new SolidPenStyle(Color.Orange, 2f.ToDip(Activity)), Width = (int)10f.ToDip(Activity), Height = (int)10f.ToDip(Activity) }, PaletteProvider = new XyCustomPaletteProvider(Color.Red, annotation) }; var ohlcSeries = new FastOhlcRenderableSeries() { DataSeries = ohlcDataSeries, PaletteProvider = new OhlcCustomPaletteProvider(Color.CornflowerBlue, annotation) }; var candlestickSeries = new FastCandlestickRenderableSeries { DataSeries = candlestickDataSeries, PaletteProvider = new OhlcCustomPaletteProvider(Color.Green, annotation) }; var columnSeries = new FastColumnRenderableSeries { DataSeries = columnDataSeries, StrokeStyle = new SolidPenStyle(Color.Blue), FillBrushStyle = new SolidBrushStyle(Color.Blue), ZeroLineY = 6000, DataPointWidth = 0.8, PaletteProvider = new XyCustomPaletteProvider(Color.Purple, annotation) }; var scatterSeries = new XyScatterRenderableSeries() { DataSeries = scatterDataSeries, PointMarker = new SquarePointMarker() { FillStyle = new SolidBrushStyle(Color.Red), StrokeStyle = new SolidPenStyle(Color.Orange, 2f.ToDip(Activity)), Width = (int)7f.ToDip(Activity), Height = (int)7f.ToDip(Activity) }, PaletteProvider = new XyCustomPaletteProvider(Color.LimeGreen, annotation) }; using (Surface.SuspendUpdates()) { Surface.XAxes.Add(xAxis); Surface.YAxes.Add(yAxis); Surface.RenderableSeries.Add(mountainSeries); Surface.RenderableSeries.Add(lineSeries); Surface.RenderableSeries.Add(ohlcSeries); Surface.RenderableSeries.Add(candlestickSeries); Surface.RenderableSeries.Add(columnSeries); Surface.RenderableSeries.Add(scatterSeries); Surface.ChartModifiers = new ChartModifierCollection { new ZoomPanModifier(), new PinchZoomModifier(), new ZoomExtentsModifier(), }; Surface.Annotations.Add(annotation); } }