Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw same width as BarWidth

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

    Draw same width as BarWidth

    Hi. I'm trying to draw a rectangle in the future (barsAgo = -1) that has same width as the bars. I'm using Draw.Line() rather than Draw.Rectangle().

    Code:
    Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, (int) ChartControl.BarWidth);

    According to the docs ChartControl.BarWidth and the Draw.Line's width parameter both are in pixels. I assumed the drawn line would have similar width to the bars but it doesn't.

    I tried converting application pixels to device pixels--

    Code:
    int devicePixelsWidth    = ChartingExtensions.ConvertToHorizontalPixels(ChartControl.BarWidth, ChartControl.PresentationSource);
    Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, devicePixelsWidth);

    The result didn't change.

    Re-scaling, reloading, whatever the width of the bars, the line is always narrower.

    Click image for larger version

Name:	bars.png
Views:	431
Size:	732 Bytes
ID:	1099709

    #2
    Hello digibob,

    Thank you for your note.

    It appears that the BarWidth parameter is the width in pixels of each side of the bar from the center to the outer edge. There's actually two ways to fix this: First, you can just multiply ChartControl.BarWidth by 2 and that should work:

    Code:
               Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, (int) (ChartControl.BarWidth *2));
    Or, more directly, ChartControl.GetBarPaintWidth() will get you the full bar paint width:

    Code:
                double barPixelWidth = ChartControl.GetBarPaintWidth(ChartControl.BarsArray[0]);
                Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, (int) (barPixelWidth));
    Either one of those options should work for you.

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

    Comment


      #3
      Hi Kate. Perfect. Many thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      71 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      152 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      100 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      288 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X