Free Support Forum - aspose.com

Setting label position in Line Chart

Dear,


I am using ASPose.Slide version: 6.5 to create a .pptx presentation. I added a Line Chart to my presentation. I added series labels using the following:

DataLabelEx lbl = new DataLabelEx(series);
lbl.Id = id; //a variable
lbl.TextFrame.Text = text; //a variable

//lbl.Position = …; --> here i need to set the position of the label

for (int i = 0; i < lbl.TextFrame.Paragraphs.Count; i++)
{
PortionFormatEx pt = lbl.TextFrame.Paragraphs[i].Portions[0].PortionFormat;
pt.FontHeight = 11;
pt.LatinFont = new FontDataEx(“Century Gothic”);
pt.FontBold = NullableBool.False;
pt.FillFormat.FillType = FillTypeEx.Solid;
pt.FillFormat.SolidFillColor.Color = Color.Black;
}
series.Labels.Add(lbl);

Is it possible to set the position of the label to “Above Line” or “Bellow Line”?
If so could you please provide me with a code snippet that will allow me to do that.

Thank you in advance,
Sami Simon

Hi Sami Simon,


I like to share that the label positions offered by Aspose.Slides are consistent with the positions available in PowerPoint. For your kind reference, I have attached the image highlighting the available label positions in Aspose.Slides. I feel, the label positions that you are requesting are unfortunately unavailable in PowerPoint as well.

Many Thanks,

Dear,


Thank you so much for your reply. I would like to apologize for expressing myself in an incorrect way. Kindly find attached a screenshot that shows the “Above” and “Bellow” label positions in a line chart.

What I need to do it to place that label of the line chart above and bellow the line very similar to the attached screenshot. Is this doable in ASPose? if yes could you please provide me with a code snippet that will allow me to do that.

Regards,
Sami Simon

Hi Sami Simon,


I have worked over the requirements shared by you. Please use the following code snippet to serve the purpose. I also like to add that the Above label position is achieved through Top position label and Below position label is achieved through Bottom position.

PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];

ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.Line, 100, 100, 300, 300);

ChartSeriesExCollection seriesCollection = chart.ChartData.Series;

ChartSeriesEx series = seriesCollection[0];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Green;

// series.Labels.Position = LegendDataLabelPositionEx.Top;
series.Labels.Position = LegendDataLabelPositionEx.Bottom;
series.Labels.ShowValue = true;
seriesCollection.RemoveAt(1);
seriesCollection.RemoveAt(1);
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Yellow;

// series = seriesCollection[2];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Cyan;

pres.Write(“D:\Aspose Data\ChartExample.pptx”);

Many Thanks,

Dear,


Thank you so much for the code snippet, I have tried it and it works great. But now, after I set the labels to Top or Bottom (using the exact same code that you provide me in your earlier reply) , I need to be able to change the label’s font size, color and font family. Could you please add the code that will allow me to do this to your earlier code snippet?

Thank you so much,
Sami Simon

Hi Sami Simon,


I regret to share that setting font related properties for the label text is currently unavailable in Aspose.Slides. An issue with ID SLIDESNET-33468 has been created in our issue tracking system to provide this feature. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

We are sorry for your inconvenience,

Dear,


I realized that ASPose.Slide for .Net 6.6.0 has been released. Is my request included in it? If so could you please provide me with a code snippet that allows me to set the label’s font size after setting its position.
Otherwise could you please tell me when could this be fixed.

Best regards,
Sami Simon

Hi Sami Simon,


I have discussed the issue with our development team about the status of the issue and regret to share that the issue has not yet been resolved. However, I have requested our development team to schedule and investigate the issue for resolution. They have scheduled the issue for investigation and ETA during Week 38 of 2012. I will be able to share the further information related to this once our development team will complete their investigation.

Many Thanks,

Hi Sami Simon,


I like to share that issue shared has been resolved in Aspose.Slides for .NET 6.7.0. Please use the following code snippet to serve the purpose. We will share the notification with you once the product release will be made available on-line by today evening.

public static void chaneLabelProperty()
{
String path = @“C:\Users\Mudassir\Downloads”;
PresentationEx pres = new PresentationEx();

//Access first slide
SlideEx sld = pres.Slides[0];

// Add chart with default data
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredBar, 0, 0, 500, 500);
//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[1];

//set general params for all labels in series
series.Labels.ShowValue = true; series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid; series.Labels.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.
Color = Color.Yellow;

//for creation custom lables with custom text use TextFrame property
DataLabelEx lbl = new DataLabelEx(series);
lbl.Id = 0;
lbl.ShowCategoryName = true;
lbl.Separator = “/”;
lbl.TextFrame.Text = “Hi Mudassir”;
lbl.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 12;
lbl.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
lbl.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Red;
lbl.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
series.Labels.Add(lbl);

//for creation custom lables with automatic generated data use “TextProperties”
lbl = new DataLabelEx(series);
lbl.Id = 1;
lbl.ShowValue = true;
lbl.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 44;
lbl.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;
lbl.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Blue;
lbl.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
series.Labels.Add(lbl);
// Save presentation with chart
pres.Write(path+“33468 out.pptx”);
}


Many Thanks,

The issues you have found earlier (filed as SLIDESNET-33468) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.