title: C# WinForms Chart Control: get Size,Region,Position of Bar
body: <p>is there a way to get the rectangles of the stackcolumn chart bar?</p>
  
  <p>this code snippet is how it can be works but it's very ugly:</p>
  
  <pre><code>            var points = new List&lt;Point&gt;();
              for (int x = 0; x &lt; chart.Size.Width; x++)
              {
                  for (int y = 0; y &lt; chart.Size.Height; y++)
                  {
                      var hp = chart.HitTest(x, y, false, ChartElementType.DataPoint);
                      var result = hp.Where(h =&gt; h.Series?.Name == "Cats");
                      if (result.Count() &gt; 0)
                      {
                          points.Add(new Point(x, y));
                      }
                  }
              }
              var bottomright = points.First();
              var topleft = points.Last();
  </code></pre>
  
  <p>I will try to describe my purpose:
  I would like to create a chart from various testresults and make this available as a HTML file. This generated Chart is inserted as an image file in the HTML document. Now, I would like to link each part of a Bar area from the Chart to an external document. Since the graphics is static, I have only the possibility to use the "MAP Area" element to make any area as a link from HTML. The "map" element requires a "rectangle", or these coordinates. That's the reason why I need the coordinator of each part of a Bar.
  I have to mention that I am not really familiar with the Chart control yet. </p>
  
  <p><a href="https://i.stack.imgur.com/Dl7lz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dl7lz.png" alt="enter image description here"></a></p>
  
  <p>The graphics is generated testweise.</p>
  
  <p><strong>[SOLVED]</strong>
  i got the solution:</p>
  
  <pre><code>            var stackedColumns = new List&lt;Tuple&lt;string,string,Rectangle&gt;&gt;();
              for (int p = 0; p &lt; chart.Series.Select(sm =&gt; sm.Points.Count).Max(); p++)
              {                               
                  var totalPoints = 0;
                  foreach (var series in chart.Series)
                  {
                      var width = int.Parse(series.GetCustomProperty("PixelPointWidth"));
                      var x = (int)area.AxisX.ValueToPixelPosition(p + 1) - (width / 2);
                      int y = (int)area.AxisY.ValueToPixelPosition(totalPoints);
                      totalPoints += series.Points.Count &gt; p ? (int)series.Points[p].YValues[0] : 0;
                      int y_total = (int)area.AxisY.ValueToPixelPosition(totalPoints);
                      var rect = new Rectangle(x, y_total, width, Math.Abs(y - y_total));
                      stackedColumns.Add(new Tuple&lt;string, string, Rectangle&gt;(series.Name, series.Points.ElementAtOrDefault(p)?.AxisLabel, rect));                        
                  }
              }
  </code></pre>
  
  <p>this workaround works for stackedcolumn and points starts at x-axis=0. 
  just the PixelPointWidth property has to be set manualy to get the right width. i have not yet found a way to get the default bar width..</p>