Plot/Draw Windows 窗体图表中的圆形

Plot/Draw Circle in WindowsForms Chart

有没有可能在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 个点应该足以得到一个漂亮的圆而不是多边形,但这取决于图表的大小。