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:	413
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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      661 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      375 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      110 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      580 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X