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();
...
}
}
}
- Ivan Voyager asked 8 years ago
- You must login to post comments
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
- Yuriy Zadereckiy answered 8 years ago
- You must login to post comments
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?
- Ivan Voyager answered 8 years ago
- last edited 8 years ago
- You must login to post comments
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
- Yuriy Zadereckiy answered 8 years ago
-
^^ 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 login to post comments
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?
- Ivan Voyager answered 8 years ago
-
Hi Ivan, In our drawing code we offset point marker centers by 0.5*Width and 0.5*Height. So if you receive a coordinate at 10,20 then this is the centre of the marker. If your marker is 7px wide then you need to draw the marker at 6.5,23.5
-
Hi Andrew, Thank you for the clarification. Could you answer my question here (similar issue for stacked charts)? https://www.scichart.com/questions/question/how-to-add-annotations-to-stacked-columns ?
- You must login to post comments
Please login first to submit.