Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon May 04, 2020 2:20 pm

Hi ,
I m using Pie chart where some of the label values are getting over lapped. even though i have used Leader Lines and all i am not able to resolve the issues.
Please find the attached documents.
i have used leader line code as well sill not able to get label values displayed in pie chart.
chart.Series[0].DataLabels.LabelValueVisible = true;
chart.Series[0].DataLabels.LeaderLinesVisible = true;
chart.Series[0].DataLabels.PercentValueVisible = true;

and also help me to make the pie chart readable ,is there any way to set the height of Leader Line so that it will be readable to user.
Please help me to resolve this issue.

Regards,
Anusha

AnuH365068
 
Posts: 13
Joined: Wed Mar 04, 2020 10:45 am

Tue May 05, 2020 1:36 am

Hello,

Thanks for your inquiry.
To help us investigate your issue more quickly and accurately, please provide your full code and your output file. You could send them to us(support@e-iceblue.com) via email. Thanks in advance for your assistance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

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;

}

AnuH365068
 
Posts: 13
Joined: Wed Mar 04, 2020 10:45 am

Wed May 06, 2020 3:18 am

Hello,

Thanks for your sharing.
Our Spire.Presentation is based on Microsoft PowerPoint. And I have verified that when creating a Pie chart with the same data and settings in Microsoft PowerPoint, the data label text also overlaps.
However, in Microsoft PowerPoint, you can manually drag the data label to avoid text overlap. And with our product, you can set the position of chart data labels to achieve the same effect. The code below is for your kind reference.
Code: Select all
    Presentation presentation = new Presentation();
    RectangleF rect1 = new RectangleF(100, 90, 780, 420);
    presentation.SlideSize.Size = new SizeF(900, 600);
    IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.Pie, rect1, false);

    chart.ChartTitle.TextProperties.Text = "Labor Efforts (Hours)";
    chart.ChartTitle.TextProperties.IsCentered = true;
    chart.ChartTitle.Height = 30;
    chart.HasTitle = true;

    DataTable dt = new DataTable();
    dt.Columns.Add("ID");
    dt.Columns.Add("EFFORT");
    dt.Rows.Add("2.0", "0");
    dt.Rows.Add("3.0", "0");
    dt.Rows.Add("4.0", "0");
    dt.Rows.Add("5.0", "1400");

    var cntsQuarters = dt.Rows.Count;
    string[] quarters = new string[cntsQuarters];
    double[] sales = new double[cntsQuarters];
    var itemsCount = 0;
    foreach (DataRow dr in dt.Rows)
    {
        quarters[itemsCount] = dr["ID"].ToString();
        var efrt = dr["EFFORT"].ToString();
        if (efrt == "")
        {
            efrt = "0.00";
        }
        sales[itemsCount] = Convert.ToDouble(efrt);
        itemsCount = itemsCount + 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;

    }
    /**Add data labels**/
    for (int i = 0; i < cntsQuarters; i++)
    {
        ChartDataLabel label = chart.Series[0].DataLabels.Add();
        label.ID = i;
        label.LabelValueVisible = true;
        label.LegendKeyVisible = false;
        label.CategoryNameVisible = false;
        label.SeriesNameVisible = false;
        label.PercentageVisible = false;
    }
    //Specifies the x location(left) and y location(top) of the dataLabel
    chart.Series[0].DataLabels[0].X = 0.0765f;
    chart.Series[0].DataLabels[0].Y = -0.0115f;
    chart.Series[0].DataLabels[1].X = 0.0025f;
    chart.Series[0].DataLabels[1].Y = -0.0115f;
    chart.Series[0].DataLabels[2].X = -0.0842f;
    chart.Series[0].DataLabels[2].Y = 0.0032f;
    /**Add data labels**/

    presentation.SaveToFile("out.pptx", FileFormat.Pptx2013);

Output:
MyOutput.png


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu May 07, 2020 11:40 am

Hi,
Thanks for the reply.
in the case where we will not be knowing how many data labels will be there for pie chart.
how this bellow code will work.please help.
//Specifies the x location(left) and y location(top) of the dataLabel
chart.Series[0].DataLabels[0].X = 0.0765f;
chart.Series[0].DataLabels[0].Y = -0.0115f;
chart.Series[0].DataLabels[1].X = 0.0025f;
chart.Series[0].DataLabels[1].Y = -0.0115f;
chart.Series[0].DataLabels[2].X = -0.0842f;
chart.Series[0].DataLabels[2].Y = 0.0032f;

we can't apply x,y location dynamically where we will not be knowing how many data labels/rows we will be having.

Please help me to resolve the issue when the data is coming dynamically.
Regards,
Anusha

AnuH365068
 
Posts: 13
Joined: Wed Mar 04, 2020 10:45 am

Fri May 08, 2020 2:07 am

Hi Anusha,

Thanks for your reply.
For your situation, I'm afraid there is no good solution. Our products cannot programmatically determine whether the dynamically generated data label text overlaps. Even in Microsoft PowerPoint, you need to open the PPT document first to determine whether the text overlaps, and then drag the overlapping data labels visually. Sorry our Spire.Presentation cannot fulfill your needs. If you have any other questions, please feel free to contact us.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Presentation