Pre loader

How to get index of data series for point marker?

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

Hello,

I want to draw labels for line series using point markers. How to get index of data series for point marker?

public class AnnotatedPointMarker : BasePointMarker
{
   public override void Draw(SciChart.Drawing.Common.IRenderContext2D context, IEnumerable<Point> centers)
   {
       base.Draw(context, centers);
       XyDataSeries<double, double> dataSeries = RenderableSeries.DataSeries as XyDataSeries<double, double>;
       foreach (var center in centers)
       {
           int index =  ???//how to get index of data series? smth like GetIndexByCenter(center)
           double yValue = _dataSeries.YValues[index];

           _textBlock.Text = yValue .ToString();
            _textBlock.MeasureArrange();
           ...
       }
   }
 }
Version
4.0.6.8482
  • You must to post comments
0
0

Hi Yuriy,

I store mapping (index, x, y) values passed into MoveTo. But, centers passed to Draw have a slightly different values, for example:

    public override void MoveTo(SciChart.Drawing.Common.IRenderContext2D context, double x, double y, int index)
    {
        if (IsInBounds(x, y))
        {
            _indexesPoints.Add(new PointInfo() { Index = index, MarkerPoint = new Point(x, y) });
        }
        base.MoveTo(context, x, y, index);
    }

    public override void Draw(IRenderContext2D context, IEnumerable<Point> centers)
    {
        var centersCount = centers.Count();
        Debug.Assert(centersCount == _indexesPoints.Count);

        IEnumerable<Point> mapped = _indexesPoints.Select(p => p.MarkerPoint);

        base.Draw(context, centers);
   }

But centers and mapped values are slightly different:

centers[204]:
[0] {15,115}    System.Windows.Point
[1] {16,115}    System.Windows.Point
[2] {18,115}    System.Windows.Point
[3] {19,115}    System.Windows.Point
[4] {21,115}    System.Windows.Point
[5] {23,115}    System.Windows.Point
...
[203]   {337,4} System.Windows.Point

mapped[204]:
[0] {16.1363636363636,116.454545454545} System.Windows.Point
[1] {17.7320052394068,116.034435261708} System.Windows.Point
[2] {19.3244619290707,116.034435261708} System.Windows.Point
[3] {20.9169186187345,116.034435261708} System.Windows.Point
[4] {22.5093753083983,116.034435261708} System.Windows.Point
[5] {24.1018319980622,116.034435261708} System.Windows.Point
...
[203]   {338.863636363636,5.54545454545454} System.Windows.Point

How do you round (x, y) values for centers?

  • You must to post comments
0
0

Hi Ivan,

Unfortunately, it is impossible for now. The only way is to switch off clustering. During clustering point indexes get lost.

However, there are some alternatives. You can consider providing you own BatchStrategy or just overridding the MoveTo method.
The index of data point arrives at that method, so you can store it and have a mapping (x,y)->index or something.

Another alternative can be hit-testing DataSeries at (x,y) , but it can be slow if called for a large number of point markers.

Hoope this helps!

Best regards,
Yuriy

  • Andrew Burnett-Thompson
    ^^ That’s actually partly true. When clustering only the top-most market at a specific location is drawn. Clustering can be disabled by setting PointMarker.BatchStrategy = new DefaultBatchStrategy();
  • You must to post comments
0
0

Hi Yuriy,

I know about AnnotatedPointMarker original example.

I use millions points per series, is it acceptable to use DefaultPointMarkerBatchStrategy in this case? I prefer to use resampling.

Original AnnotatedPointMarker example is not acceptable for me, because dataPointIndexes.Count is not equal markerLocations.Length in zooming case (after zoom in), so this invokes inconsistency in matching dataPointIndexes & markerLocations:

var metadata = _dataPointMetadata[_dataPointIndexes[i]] as BudgetPointMetadata;

For example, markerLocations.Length == 400, dataPointIndexes.Count == 803.

How to avoid inconsistency in matching dataPointIndexes and markerLocations? What about additional PointMetadata memory usage in case when millions points are used?

  • You must to post comments
0
0

Hi Ivan,

Please take a look at the AnnotatedPointMarker class from the Series With Metadata example. This is the only way how this can be achieved for now.

Please bear in mind that you would probably need to switch PointMarker clustering off. The explanation can be found in this thread.
To do this, set the PointMarkerBatchStrategy property on PointMarker to DefaultPointMarkerBatchStrategy.

Best regards,
Yuriy

  • You must to post comments
Showing 4 results
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