Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 is too cool for me.

like image 497
CatNamedKat Avatar asked Dec 05 '15 11:12

CatNamedKat


1 Answers

Here's a code-example how you could create a pie chart. I hope this helps:

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);
}
like image 100
Tamwe Avatar answered Sep 30 '22 13:09

Tamwe