I should draw a circle inside a polar chart with some text on it.
I started to play with PostPaint, got chart graphics, so I am able to draw and write custom things on i
The self-answered solution neither works in a more general case nor does it actually transform DataPoint
values to pixel-coordinates.
Here is a solution to draw the circle that will always work:
private void chart1_PostPaint(object sender, ChartPaintEventArgs e)
{
RectangleF ipp = InnerPlotPositionClientRectangle(chart1, chart1.ChartAreas[0]);
using (Graphics g = chart1.CreateGraphics())
g.DrawEllipse(Pens.Red, new RectangleF(ipp.Location, ipp.Size));
}
It makes use of two helper functions:
RectangleF ChartAreaClientRectangle(Chart chart, ChartArea CA)
{
RectangleF CAR = CA.Position.ToRectangleF();
float pw = chart.ClientSize.Width / 100f;
float ph = chart.ClientSize.Height / 100f;
return new RectangleF(pw * CAR.X, ph * CAR.Y, pw * CAR.Width, ph * CAR.Height);
}
RectangleF InnerPlotPositionClientRectangle(Chart chart, ChartArea CA)
{
RectangleF IPP = CA.InnerPlotPosition.ToRectangleF();
RectangleF CArp = ChartAreaClientRectangle(chart, CA);
float pw = CArp.Width / 100f;
float ph = CArp.Height / 100f;
return new RectangleF(CArp.X + pw * IPP.X, CArp.Y + ph * IPP.Y,
pw * IPP.Width, ph * IPP.Height);
}
And here is a link to a general coordinate transformation function for polar charts.