是否有可能在WindowsForm Chart
中绘制一个圆?
如下所示的方法调用会非常好!
Graph.Series["circle"].Circle.Add(centerX, centerY, radius);
嗯,我为自己创建了一个解决方案。也许对某人有帮助
public void DrawCircle(Chart Graph, double centerX, double centerY, double radius, int amountOfEdges)
{
string name = "circle_" + centerX + centerY + radius + amountOfEdges;
// Create new data series
if (Graph.Series.IndexOf(name) == -1)
Graph.Series.Add(name);
// preferences of the line
Graph.Series[name].ChartType = SeriesChartType.Spline;
Graph.Series[name].Color = Color.FromArgb(0, 0, 0);
Graph.Series[name].BorderWidth = 1;
Graph.Series[name].IsVisibleInLegend = false;
// add line segments (first one also as last one)
for (int k = 0; k <= amountOfEdges; k++)
{
double x = centerX + radius * Math.Cos(k * 2 * Math.PI / amountOfEdges);
double y = centerY + radius * Math.Sin(k * 2 * Math.PI / amountOfEdges);
Graph.Series[name].Points.AddXY(x, y);
}
}
例如,您可以通过以下方式调用它
DrawCircle(Graph, 5, 4, 3, 30);
大约30点应该足以获得一个漂亮的圆形而不是多边形,但是要取决于图表的大小。