SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

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.