Pre loader

Changing style for most recent item of a live chart

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

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?

  • You must to post comments
0
0

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

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies