C#
C# / 원그래프, 차트, PieChart 그리기.
캬옹냐옹
2021. 12. 17. 14:32
728x90

폼에 chart 를 추가 한다.
private void Form1_Shown(object sender, EventArgs e)
{
DrawPieChart(chart1, "R0000-0001", 10, 20, 30, 40, 50);
}
private void DrawPieChart(Chart chart, string title, int value1, int value2, int value3, int value4, int value5)
{
//reset your chart series and legends
chart.Series.Clear();
chart.Legends.Clear();
//Add a new Legend(if needed) and do some formating
chart.Legends.Add("MyLegend");
chart.Legends[0].LegendStyle = LegendStyle.Table;
chart.Legends[0].Docking = Docking.Bottom;
chart.Legends[0].Alignment = StringAlignment.Center;
chart.Legends[0].Title = title;
chart.Legends[0].BorderColor = Color.Black;
//Add a new chart-series
string seriesname = "MySeriesName";
chart.Series.Add(seriesname);
//set the chart-type to "Pie"
chart.Series[seriesname].ChartType = SeriesChartType.Pie;
//Add some datapoints so the series. in this case you can pass the values to this method
chart.Series[seriesname].Points.AddXY("MyPointName", value1);
chart.Series[seriesname].Points.AddXY("MyPointName1", value2);
chart.Series[seriesname].Points.AddXY("MyPointName2", value3);
chart.Series[seriesname].Points.AddXY("MyPointName3", value4);
chart.Series[seriesname].Points.AddXY("MyPointName4", value5);
}
위에 코드를 추가 한다.

짠 원하던 원그래프가 등장한다.
끝!
출처: https://stackoverflow.com/questions/34104484/how-to-build-a-pie-chart-based-on-int-values
How to build a pie chart based on int values
I have some int variables and I need to create a pie chart based on them in a visual studio form. How do I link them together as I seem to only be able to find how to link it to a database, which i...
stackoverflow.com
728x90