C# 如何基于int值构建饼图
我有一些int变量,需要在VisualStudio表单中基于它们创建一个饼图。C# 如何基于int值构建饼图,c#,visual-studio,pie-chart,C#,Visual Studio,Pie Chart,我有一些int变量,需要在VisualStudio表单中基于它们创建一个饼图。 如何将它们链接在一起,因为我似乎只能找到如何将其链接到数据库,这对我来说太酷了。下面是一个代码示例,说明如何创建饼图。我希望这有助于: private void DrawPieChart(int value1, int value2, int value3, int value4, int value5) { //reset your chart series and legends chart1.S
如何将它们链接在一起,因为我似乎只能找到如何将其链接到数据库,这对我来说太酷了。下面是一个代码示例,说明如何创建饼图。我希望这有助于:
private void DrawPieChart(int value1, int value2, int value3, int value4, int value5)
{
//reset your chart series and legends
chart1.Series.Clear();
chart1.Legends.Clear();
//Add a new Legend(if needed) and do some formating
chart1.Legends.Add("MyLegend");
chart1.Legends[0].LegendStyle = LegendStyle.Table;
chart1.Legends[0].Docking = Docking.Bottom;
chart1.Legends[0].Alignment = StringAlignment.Center;
chart1.Legends[0].Title = "MyTitle";
chart1.Legends[0].BorderColor = Color.Black;
//Add a new chart-series
string seriesname = "MySeriesName";
chart1.Series.Add(seriesname);
//set the chart-type to "Pie"
chart1.Series[seriesname].ChartType = SeriesChartType.Pie;
//Add some datapoints so the series. in this case you can pass the values to this method
chart1.Series[seriesname].Points.AddXY("MyPointName", value1);
chart1.Series[seriesname].Points.AddXY("MyPointName1", value2);
chart1.Series[seriesname].Points.AddXY("MyPointName2", value3);
chart1.Series[seriesname].Points.AddXY("MyPointName3", value4);
chart1.Series[seriesname].Points.AddXY("MyPointName4", value5);
}
“窗体”是指windows窗体吗?或者您正在使用WPF?在窗体上放置一个图表控件,并将其设置为显示饼图类型!图表位于工具箱的数据面板中。还可以使用System.Windows.Forms.DataVisualization.Charting添加名称空间
代码>以便于访问属性!您只需将整数作为值添加到series.points.add调用中..是的,我已经添加了图表,但是您能否详细说明series.points中的值。。。因为我在那里找不到你了。我尝试在末尾添加chart1.SaveImage(“sample.png”,System.Drawing.Imaging.ImageFormat.png)
。但是sample.png文件只是一个空白的白屏,有人能纠正一下原因吗?