Another question – is it possible to set the style of the most recent point in a chart? Like putting a “ball” or something visually larger onto the most recent item of the chart?
- plytle asked 11 years ago
- You must login to post comments
Hey there,
You could achieve this in a few ways, check out our demo Annotations are Easy. One of the annotation types is an Axis Marker annotation (displays an arrow with Y-value in the YAxis).
You could create a custom ChartModifier which positioned the AxisMarkerAnnotation on redraw. Some code below:
// NOTE: I have not tested this, but it demonstrates the concept // 1. Inherit ChartModifierBase // 2. Override OnParentSurfaceRendered // 3. Iterate over RenderableSeries // 4. Get DataSeries.YValues.Last() // 5. Add AxisMarkerAnnotation with this Y-Value public class SeriesValueModifier : ChartModifierBase { private IList<IAnnotation> myAxisMarkers = new List<IAnnotation>(); public override void OnParentSurfaceRendered(SciChartRenderedMessage e) { base.OnParentSurfaceRendered(e); ClearAxisMarkers(); if (ParentSurface.RenderableSeries == null || ParentSurface.RenderableSeries.Count == 0) return; foreach (var renderableSeries in ParentSurface.RenderableSeries) { if (renderableSeries == null || renderableSeries.DataSeries == null) { continue; } // Get the latest value of the DataSeries // This assumes Y-Values are doubles var latestYValue = (double)renderableSeries.DataSeries.YValues[renderableSeries.DataSeries.Count - 1]; var axisMarker = new AxisMarkerAnnotation() {Y1 = latestYValue, Background = new SolidColorBrush(renderableSeries.SeriesColor)}; myAxisMarkers.Add(axisMarker); ParentSurface.Annotations.Add(axisMarker); } } // NOTE: In reality rather than clearing/re-adding all axis markers, it will be far more // efficient, and probably less flickery, to re-use AxisMarkerAnnotations and reposition them, // only adding/removing when the RenderableSeries count changes. private void ClearAxisMarkers() { foreach (var axisMarker in myAxisMarkers) { ParentSurface.Annotations.Remove(axisMarker); } } }
Note: To change this to display an ellipse at the actual series X,Y value would be quite easy. Instead of AxisMarkerAnnotation create a custom annotation which has an ellipse shape, get the last X and Y value of the series, and set EllipseAnnotation.X1 = x, EllipseAnnotation.Y1 = y.
I hope this helps!
Andrew
- Andrew Burnett-Thompson answered 11 years ago
- You must login to post comments
Please login first to submit.