Thursday, 15 January 2015

c# - Visual Studio Pie Chart - Generate Percentages -


I am generating pie charts by dragging data from the SQL table. Data is a collection of hours for various projects.

The chart is fine, but I would like to display the pie graph related percentage of each piece of pie, which is being used when the graph is generated.

I am making charts in the manner shown below () . [[Series 1]]. Points. ADACI (project [i], progetime [ii]); } Chart 6 Series [0] ["Pylebell Style"] = "Disabled";

I was hoping that I can pass a simple order in the back code to make it, but handcrafted on the web provides usable results without any reason. But these are not the options in Visual Studio Express 2013.

Prepare this way:

  chain s = chart 6 . Series ["Series 1"]; S.ChartType = SeriesChartType.Pie; S.IsValueShownAsLabel = True; S ["PieLabelStyle"] = "Out";  

If you know the total, then make a datapoint like this:

  Datapoint page = new datapoint (project [i], progetime [i]) ; // Check your data type for calculation! P.Label = p.YValues ​​[0] + "H = \ n" + (100d * p.YValues ​​[0] / total). Ostring ("00.00") + "% \ n"; // my format  

enter image details here

If you do not know the total, set the first digit, then calculate the total and set the label at the end:

 For  (int i = 0; i & lt; = Index-1; I ++) {SPNADAC. (Project [i], Progetime [ii]); } // Total Count: Double Total = S. Points SUM (DP => DPY Values ​​[0]); // Now we can set the percentage foreach (Datapoint P in SP Points) {p.Label = p.YValues ​​[0] + "H = \ n" + (100d * p.YValues ​​[0] / Total). Stressing ("00.00") + "% \ n"; // my format} chart1.Titles.Add (SP number. + "Projects, Total" + Total .tostring ("###, ## 0") + "Hours"); Chart1.Titles [0] .Font = new System.Drawing.Font ("Arial", 14f);  

No comments:

Post a Comment