Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Get the Last Bar's Pixel Location

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to Get the Last Bar's Pixel Location

    Hi,

    I need to constrain an anchor to not go past the last visible bar on the chart. For example, if I have a chart that has a Right Side Margin of say 350 pixels. How do I prevent the anchor from being dropped/moved beyond the last visible bar?

    I can find the right-most bar by using chartsBars.ToIndex but how do I compare the pixel location of ToIndex with ChartAnchor dataPoint?
    Last edited by Kabua; 10-17-2019, 07:31 AM.

    #2
    Hello Kabua,

    Thank you for your post.

    You could get the index of the last visible bar with ChartBars.ToIndex, yes. You can then get the chart-canvas coordinate of that bar using GetXByBarIndex:



    Once you've got the application pixels, you can convert them to device pixels using ConvertToHorizontalPixels:



    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thank you. I had the GetXByBarIndex but I couldn't figure out the ConvertToPixel function.

      For anyone looks for the same here's my code:

      Code:
                      var point = dataPoint.GetPoint(chartControl, chartPanel, chartScale);
      
                      var lastX = chartControl.GetXByBarIndex(GetAttachedToChartBars(), chartControl.PrimaryBars.ToIndex - 1);
                      var lastDevicePixelX = ChartingExtensions.ConvertToHorizontalPixels(lastX, chartControl.PresentationSource);
      
                      if (point.X > lastDevicePixelX)
                      {
                          // Do something...
                      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      93 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      138 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      123 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      73 views
      0 likes
      Last Post PaulMohn  
      Working...
      X