簡體   English   中英

在 WindowsForms 圖表中繪制/繪制圓圈

[英]Plot/Draw Circle in WindowsForms Chart

plot 是否有可能在WindowsForm Chart中畫一個圓圈?

如下的方法調用會非常好!

Graph.Series["circle"].Circle.Add(centerX, centerY, radius);

w

好吧,我為自己創造了一個解決方法。 也許它可以幫助某人

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 個點應該足以得到一個漂亮的圓形而不是多邊形,但這取決於圖表的大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM