public MainViewModel() { var dummyDataProvider = new DummyDataProvider(); var lineData = new XyDataSeries <double, double>() { SeriesName = "TestingSeries" }; _renderableSeries = new ObservableCollection <IRenderableSeriesViewModel>(); RenderableSeries.Add(new LineRenderableSeriesViewModel() { StrokeThickness = 2, Stroke = Colors.SteelBlue, DataSeries = lineData, StyleKey = "LineSeriesStyle" }); // Append the initial values to the chart var initialDataValues = dummyDataProvider.GetHistoricalData(); lineData.Append(initialDataValues.XValues, initialDataValues.YValues); // Subscribe to future updates dummyDataProvider.SubscribeUpdates((newValues) => { // Append when new values arrive lineData.Append(newValues.XValues, newValues.YValues); // Zoom the chart to fit lineData.InvalidateParentSurface(RangeMode.ZoomToFit); }); }
private void SetSeries(string seriesType) { RenderableSeries.Clear(); if (seriesType.Equals("Column Series")) { RenderableSeries.Add(_columnSeries); } else if (seriesType.Equals("Impulse Series")) { RenderableSeries.Add(_impulseSeries); } else if (seriesType.Equals("Mountain Series")) { RenderableSeries.Add(_mountainSeries); } else if (seriesType.Equals("PointLine Series")) { RenderableSeries.Add(_pointLineSeries); } else if (seriesType.Equals("SurfaceMesh Series")) { RenderableSeries.Add(_surfaceMeshSeries); } // Temporary //else if (seriesType.Equals("Waterfall Series")) //{ // RenderableSeries.Add(_waterfallSeries); //} else if (seriesType.Equals("Scatter Series")) { RenderableSeries.Add(_scatterSeries); } }
private void SeriesUpdate() { if (RenderableSeries != null) { RenderableSeries.Clear(); RenderableSeries.Add(new ColumnRenderableSeriesViewModel() { DataPointWidth = 1, Stroke = System.Windows.Media.Color.FromRgb(186, 187, 190), DataSeries = Series }); } if (Data != null && Series != null) { XList.Clear(); YList.Clear(); XList = Data.Keys.ToList(); YList = Data.Values.ToList(); try { Series.Clear(); Series.InsertRange(0, XList, YList); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void CreateChartSeries() { // Create a RenderableSeries. Apply the DataSeries created before _renderableSeries = new ObservableCollection <IRenderableSeriesViewModel>(); RenderableSeries.Add(new LineRenderableSeriesViewModel() { StrokeThickness = 2, Stroke = Colors.SteelBlue, DataSeries = _lineData, StyleKey = "LineSeriesStyle" }); }
private void InitializeRenderableSeries() { var renderableSeries = new LineRenderableSeriesViewModel { Stroke = Colors.Blue, StrokeThickness = 2, PointMarker = new EllipsePointMarker() }; var dataSeries = new XyDataSeries <double>(); for (int i = 0; i < 11; ++i) { dataSeries.Append(i, i - 3); } renderableSeries.DataSeries = dataSeries; RenderableSeries.Add(renderableSeries); }
public MainViewModel() { var lineData = new XyDataSeries <double, double>() { SeriesName = "TestingSeries" }; lineData.Append(0, 0); lineData.Append(1, 1); lineData.Append(2, 2); _renderableSeries = new ObservableCollection <IRenderableSeriesViewModel>(); RenderableSeries.Add(new LineRenderableSeriesViewModel() { StrokeThickness = 2, Stroke = Colors.SteelBlue, DataSeries = lineData, }); }
public override HitTestInfo HitTest(Point rawPoint, double hitTestRadius, bool interpolate = false) { var nearestBaseHitResult = base.HitTest(rawPoint, hitTestRadius, interpolate); // No spline? Fine - return base implementation if (!RenderableSeries.IsSplineEnabled || RenderableSeries._splineSeries == null || RenderableSeries.CurrentRenderPassData == null) { return(nearestBaseHitResult); } var nearestHitResult = new HitTestInfo(); // Get the coordinateCalculators. See 'Converting Pixel Coordinates to Data Coordinates' documentation for coordinate transforms var xCalc = RenderableSeries.CurrentRenderPassData.XCoordinateCalculator; // Compute the X,Y data value at the mouse location var xDataPointAtMouse = xCalc.GetDataValue(RenderableSeries.CurrentRenderPassData.IsVerticalChart ? rawPoint.Y : rawPoint.X); // Find the index in the spline interpolated data that is nearest to the X-Data point at mouse // NOTE: This assumes the data is sorted in ascending direction and a binary search would be faster ... int foundIndex = RenderableSeries.FindIndex(RenderableSeries._splineSeries, xDataPointAtMouse); if (foundIndex != -1) { nearestHitResult.IsWithinDataBounds = true; // Find the nearest data point to the mouse var xDataPointNearest = RenderableSeries._splineSeries[foundIndex].X; var yDataPointNearest = RenderableSeries._splineSeries[foundIndex].Y; nearestHitResult.XValue = xDataPointNearest; nearestHitResult.YValue = yDataPointNearest; // Compute the X,Y coordinates (pixel coords) of the nearest data point to the mouse nearestHitResult.HitTestPoint = nearestHitResult.HitTestPoint = RenderableSeries.GetCoordinatesFor(xDataPointNearest, yDataPointNearest); // Determine if mouse-location is within 7.07 pixels of the nearest data point var distance = Math.Pow(rawPoint.X - nearestHitResult.HitTestPoint.X, 2) + Math.Pow(rawPoint.Y - nearestHitResult.HitTestPoint.Y, 2); distance = Math.Sqrt(distance); var baseDistance = Math.Pow(rawPoint.X - nearestBaseHitResult.HitTestPoint.X, 2) + Math.Pow(rawPoint.Y - nearestBaseHitResult.HitTestPoint.Y, 2); baseDistance = Math.Sqrt(baseDistance); nearestHitResult.IsHit = distance <= DefaultHitTestRadius || baseDistance <= DefaultHitTestRadius; nearestHitResult.IsVerticalHit = true; nearestHitResult.DataSeriesIndex = nearestBaseHitResult.DataSeriesIndex; if (RenderableSeries.DataSeries.HasMetadata) { nearestHitResult.Metadata = RenderableSeries.DataSeries.Metadata[nearestHitResult.DataSeriesIndex]; } // Returning a HitTestResult with IsHit = true / IsVerticalHit signifies to the Rollovermodifier & TooltipModifier to show a tooltip at this location return(nearestHitResult); } else { // Returning HitTestInfo.Empty signifies to the RolloverModifier & TooltipModifier there is nothing to show here return(HitTestInfo.Empty); } }