繁体   English   中英

如何基于int值构建饼图

[英]How to build a pie chart based on int values

我有一些int变量,我需要在visual studio表单中创建一个基于它们的饼图。 我如何将它们链接在一起,因为我似乎只能找到如何将它链接到数据库,这对我来说太酷了。

这是一个代码示例,您可以如何创建饼图。 我希望这有帮助:

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM