Gargi Patil

Gargi Patil

  • 2k
  • 51
  • 1.7k

Annotation should be update while moving cursor.

May 20 2021 12:16 PM
Hello,So I have created a PointLineSeries in LightningChart, and I would like to add annotations to the line when I hover the mouse over it. I have written code to show the annotion box and it moves when I move the cursor, but it is blank. How can I add the value to this box? Any help would be appreciated.
  1. private void UpdateCursorResult()    
  2. {  
  3. _updatedCursorResults = true;  
  4. _chart.BeginUpdate();  
  5. LineSeriesCursor cursor = _chart.ViewXY.LineSeriesCursors[0];    
  6. AnnotationXY annot = _chart.ViewXY.Annotations[0];    
  7. float targetYCoordinate = DpiHelper.DipToPx((float)_chartViewXY.GetMarginsRect().Bottom);    
  8. double y;    
  9. _chart.ViewXY.YAxes[0].CoordToValue(targetYCoordinate, out y, false);    
  10. annot.TargetAxisValues.X = cursor.ValueAtXAxis;    
  11. annot.TargetAxisValues.Y = y;  
  12. double seriesYValue = 0.0;    
  13. StringBuilder sb = new StringBuilder();    
  14. int seriesNumber = 1;    
  15. char c = 'A';    
  16. string channelStringFormat = "Product {0}: {2,5}";    
  17. string value = "";    
  18. AxisY yAxis = null;  
  19. foreach (PointLineSeries series in _chart.ViewXY.PointLineSeries)    
  20. {    
  21. value = "";    
  22. seriesYValue = GetTotalSum((int)cursor.ValueAtXAxis, (Product)(seriesNumber - 1));    
  23. yAxis = _chart.ViewXY.YAxes[series.AssignYAxisIndex];    
  24. value = string.Format(channelStringFormat, c, ConvertToCurrencyString(seriesYValue));    
  25. sb.AppendLine(value);  
  26. seriesNumber++;    
  27. c++;    
  28. }  
  29. channelStringFormat = "Total sales: {0,8}";    
  30. value = string.Format(channelStringFormat, ConvertToCurrencyString(GetTotalSum((int)cursor.ValueAtXAxis)));    
  31. sb.AppendLine("");    
  32. sb.AppendLine(value);  
  33. annot.Visible = true;  
  34. _chart.EndUpdate();    
  35. }