Tue May 05, 2020 1:06 pm
Hi,
Please find the code used to generate Pie chart.
RectangleF rect1 = new RectangleF(100, 90, 780, 420);
Spire.Presentation.Charts.IChart chart = presentation.Slides[Slideno].Shapes.AppendChart(Spire.Presentation.Charts.ChartType.Pie, rect1, false);
///Spire.Presentation.Charts.IChart chart1 = presentation.Slides[Slideno].Shapes.AppendChart(Spire.Presentation.Charts.ChartType.ColumnStacked, rect);
chart.ChartTitle.TextProperties.Text = "Labor Efforts (Hours)";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
var cntsQuarters = objDs.Tables[tbleNbr].Rows.Count;
//string[] quarters = new string[] { "Material ($)", "Outsource ($)", "Pass Thru ($)", "ODC ($)", "Travel ($)", "Facilities ($)" };
string[] quarters = new string[cntsQuarters];
double[] sales = new double[cntsQuarters];
var itemsCount = 0;
foreach (DataRow dr in objDs.Tables[tbleNbr].Rows)
{
quarters[itemsCount] = dr["ID"].ToString();
var efrt =dr["EFFORT"].ToString();
if (efrt == "")
{
efrt = "0.00";
}
laborEffortsHrs = Convert.ToDouble(efrt);
sales[itemsCount] = Convert.ToDouble(efrt);
itemsCount = itemsCount + 1;
}
var cnts = objDs.Tables[tbleNbr].Rows.Count - 1;
chart.ChartData[0, 0].Text = "Labor Efforts (Hours)";
chart.ChartData[0, 1].Text = "Labor Efforts (Hours)";
for (int i = 0; i < quarters.Length; ++i)
{
chart.ChartData[i + 1, 0].Value = quarters[i];
chart.ChartData[i + 1, 1].Value = sales[i];
}
chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
chart.Categories.CategoryLabels = chart.ChartData["A2", "A" + (quarters.Length + 1)];
chart.Series[0].Values = chart.ChartData["B2", "B" + (quarters.Length + 1)];
for (int i = 0; i < chart.Series[0].Values.Count; i++)
{
Spire.Presentation.Charts.ChartDataPoint cdp = new Spire.Presentation.Charts.ChartDataPoint(chart.Series[0]);
cdp.Index = i;
chart.Series[0].DataPoints.Add(cdp);
}
var seriescnt = quarters.Length;
if (seriescnt < 15)
{
chart.Series[0].DataLabels.LabelValueVisible = true;
chart.Series[0].DataLabels.LeaderLinesVisible = true;
chart.Series[0].DataLabels.PercentValueVisible = false;
chart.ChartLegend.Position = 0;
}
else
{
chart.Series[0].DataLabels.LabelValueVisible = false;
//chart.Series[0].DataLabels.LeaderLinesVisible = true;
chart.Series[0].DataLabels.PercentValueVisible = false;
chart.ChartLegend.Position = 0;
}