protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our chart from the layout resource, var chart = FindViewById <SciChartSurface>(Resource.Id.Chart); // Create a numeric X axis var xAxis = new NumericAxis(this) { AxisTitle = "Number of Samples (per Series)" }; // Create a numeric Y axis var yAxis = new NumericAxis(this) { AxisTitle = "Value", VisibleRange = new DoubleRange(-1, 1) }; // Add xAxis to the XAxes collection of the chart chart.XAxes.Add(xAxis); // Add yAxis to the YAxes collection of the chart chart.YAxes.Add(yAxis); // Create XyDataSeries to host data for our chart var lineData = new XyDataSeries <double, double>() { SeriesName = "Sin(x)" }; var scatterData = new XyDataSeries <double, double>() { SeriesName = "Cos(x)" }; // Append data which should be drawn for (var i = 0; i < 1000; i++) { lineData.Append(i, Math.Sin(i * 0.1)); scatterData.Append(i, Math.Cos(i * 0.1)); } double phase = 0; var timer = new Timer(30) { AutoReset = true }; var lineBuffer = new DoubleValues(1000); var scatterBuffer = new DoubleValues(1000); // Update on each tick of timer timer.Elapsed += (s, e) => { lineBuffer.Clear(); scatterBuffer.Clear(); for (int i = 0; i < 1000; i++) { lineBuffer.Add(Math.Sin(i * 0.1 + phase)); scatterBuffer.Add(Math.Cos(i * 0.1 + phase)); } using (chart.SuspendUpdates()) { lineData.UpdateRangeYAt(0, lineBuffer); scatterData.UpdateRangeYAt(0, scatterBuffer); } phase += 0.01; }; timer.Start(); var lineSeries = new FastLineRenderableSeries() { DataSeries = lineData, StrokeStyle = new SolidPenStyle(Color.LightBlue, 2) }; // Create scatter series with data appended into scatterData var scatterSeries = new XyScatterRenderableSeries() { DataSeries = scatterData, PointMarker = new EllipsePointMarker() { Width = 10, Height = 10, StrokeStyle = new SolidPenStyle(Color.Green, 2), FillStyle = new SolidBrushStyle(Color.LightBlue) } }; // Add the renderable series to the RenderableSeries collection of the chart chart.RenderableSeries.Add(lineSeries); chart.RenderableSeries.Add(scatterSeries); // Create interactivity modifiers var pinchZoomModifier = new PinchZoomModifier(); pinchZoomModifier.SetReceiveHandledEvents(true); var zoomPanModifier = new ZoomPanModifier(); zoomPanModifier.SetReceiveHandledEvents(true); var zoomExtentsModifier = new ZoomExtentsModifier(); zoomExtentsModifier.SetReceiveHandledEvents(true); var yAxisDragModifier = new YAxisDragModifier(); yAxisDragModifier.SetReceiveHandledEvents(true); // Create and configure legend var legendModifier = new LegendModifier(this); legendModifier.SetLegendPosition(GravityFlags.Bottom | GravityFlags.CenterHorizontal, 10); legendModifier.SetOrientation(Orientation.Horizontal); // Create RolloverModifier to show tooltips var rolloverModifier = new RolloverModifier(); rolloverModifier.SetReceiveHandledEvents(true); // Create modifier group from declared modifiers var modifiers = new ModifierGroup(pinchZoomModifier, zoomPanModifier, zoomExtentsModifier, yAxisDragModifier, rolloverModifier, legendModifier); // Add the interactions to the ChartModifiers collection of the chart chart.ChartModifiers.Add(modifiers); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our chart from the layout resource, var chart = FindViewById <SciChartSurface>(Resource.Id.Chart); // Create a numeric X axis var xAxis = new NumericAxis(this) { AxisTitle = "Number of Samples (per Series)" }; // Create a numeric Y axis var yAxis = new NumericAxis(this) { AxisTitle = "Value", VisibleRange = new DoubleRange(-1, 1) }; // Create a secondary numeric Y Axis var secondaryYAxis = new NumericAxis(this) { AxisTitle = "Secondary", AxisId = "SecondaryAxis", AxisAlignment = AxisAlignment.Left, VisibleRange = new DoubleRange(-2, 2) }; // Add xAxis to the XAxes collection of the chart chart.XAxes.Add(xAxis); // Add yAxis to the YAxes collection of the chart chart.YAxes.Add(yAxis); // Add secondaryYAxis to the YAxes collection of the chart chart.YAxes.Add(secondaryYAxis); const int fifoCapacity = 500; // Create XyDataSeries to host data for our chart var lineData = new XyDataSeries <double, double>() { SeriesName = "Sin(x)", FifoCapacity = new Integer(fifoCapacity) }; var scatterData = new XyDataSeries <double, double>() { SeriesName = "Cos(x)", FifoCapacity = new Integer(fifoCapacity) }; var timer = new Timer(30) { AutoReset = true }; var x = lineData.Count; // Append on each tick of timer timer.Elapsed += (s, e) => { using (chart.SuspendUpdates()) { lineData.Append(x, Math.Sin(x * 0.1)); scatterData.Append(x, Math.Cos(x * 0.1)); // add label every 100 data points if (x % 100 == 0) { // create text annotation with label var label = new TextAnnotation(this) { Text = "N", X1Value = x, Y1Value = 0, HorizontalAnchorPoint = HorizontalAnchorPoint.Center, VerticalAnchorPoint = VerticalAnchorPoint.Center, FontStyle = new FontStyle(20, Color.White), Background = new ColorDrawable(Color.DarkGreen), ZIndex = 1, YAxisId = x % 200 == 0 ? AxisBase.DefaultAxisId : "SecondaryAxis" }; // add label into annotation collection chart.Annotations.Add(label); // if we add annotation and x > fifoCapacity // then we need to remove annotation which goes out of the screen if (x > fifoCapacity) { chart.Annotations.Remove(0); } } // zoom series to fit viewport size into XAxis direction chart.ZoomExtentsX(); x++; } }; timer.Start(); // Create line series with data appended into lineData var lineSeries = new FastLineRenderableSeries() { DataSeries = lineData, StrokeStyle = new SolidPenStyle(Color.LightBlue, 2) }; // Create scatter series with data appended into scatterData var scatterSeries = new XyScatterRenderableSeries() { DataSeries = scatterData, PointMarker = new EllipsePointMarker() { Width = 10, Height = 10, StrokeStyle = new SolidPenStyle(Color.Green, 2), FillStyle = new SolidBrushStyle(Color.LightBlue) }, YAxisId = "SecondaryAxis" }; // Add the renderable series to the RenderableSeries collection of the chart chart.RenderableSeries.Add(lineSeries); chart.RenderableSeries.Add(scatterSeries); // Create interactivity modifiers var pinchZoomModifier = new PinchZoomModifier(); pinchZoomModifier.SetReceiveHandledEvents(true); var zoomPanModifier = new ZoomPanModifier(); zoomPanModifier.SetReceiveHandledEvents(true); var zoomExtentsModifier = new ZoomExtentsModifier(); zoomExtentsModifier.SetReceiveHandledEvents(true); var yAxisDragModifier = new YAxisDragModifier(); yAxisDragModifier.SetReceiveHandledEvents(true); // Create and configure legend var legendModifier = new LegendModifier(this); legendModifier.SetLegendPosition(GravityFlags.Bottom | GravityFlags.CenterHorizontal, 10); legendModifier.SetOrientation(Orientation.Horizontal); // Create RolloverModifier to show tooltips var rolloverModifier = new RolloverModifier(); rolloverModifier.SetReceiveHandledEvents(true); // Create modifier group from declared modifiers var modifiers = new ModifierGroup(pinchZoomModifier, zoomPanModifier, zoomExtentsModifier, yAxisDragModifier, rolloverModifier, legendModifier); // Add the interactions to the ChartModifiers collection of the chart chart.ChartModifiers.Add(modifiers); }
public static LegendModifier WithOrientation(this LegendModifier legendModifier, Orientation orientation) { legendModifier.SetOrientation(orientation); return(legendModifier); }
private void InitChart(SciChartSurface chart) { // Create a numeric X axis var xAxis = new NumericAxis(this) { AxisTitle = "Number of Samples (per Series)" }; // Create a numeric Y axis var yAxis = new NumericAxis(this) { AxisTitle = "Value", VisibleRange = new DoubleRange(-1, 1) }; // Create a secondary numeric Y Axis var secondaryYAxis = new NumericAxis(this) { AxisTitle = "Secondary", AxisId = "SecondaryAxis", AxisAlignment = AxisAlignment.Left, VisibleRange = new DoubleRange(-2, 2) }; // Create interactivity modifiers var pinchZoomModifier = new PinchZoomModifier(); pinchZoomModifier.SetReceiveHandledEvents(true); var zoomPanModifier = new ZoomPanModifier(); zoomPanModifier.SetReceiveHandledEvents(true); var zoomExtentsModifier = new ZoomExtentsModifier(); zoomExtentsModifier.SetReceiveHandledEvents(true); // Create RolloverModifier to show tooltips var rolloverModifier = new RolloverModifier(); rolloverModifier.SetReceiveHandledEvents(true); var yAxisDragModifier = new YAxisDragModifier(); yAxisDragModifier.SetReceiveHandledEvents(true); // Create and configure legend var legendModifier = new LegendModifier(this); legendModifier.SetLegendPosition(GravityFlags.Bottom | GravityFlags.CenterHorizontal, 10); legendModifier.SetOrientation(Orientation.Horizontal); var modifiers = new ModifierGroup(pinchZoomModifier, zoomPanModifier, zoomExtentsModifier, rolloverModifier, legendModifier, yAxisDragModifier); modifiers.SetReceiveHandledEvents(true); modifiers.MotionEventGroup = "SharedEvents"; // Add xAxis to the XAxes collection of the chart chart.XAxes.Add(xAxis); // Add yAxis to the YAxes collection of the chart chart.YAxes.Add(yAxis); // Add secondaryYAxis to the YAxes collection of the chart chart.YAxes.Add(secondaryYAxis); // Add the interactions to the ChartModifiers collection of the chart chart.ChartModifiers.Add(modifiers); }