Free Support Forum - aspose.com

Putting a border round a data label

Hi I'm trying to figure out how to choose one data point in a series and change the font colour (or size, or bold it, what ever).

But I'm not sure how to reference a particular point in a series.

fact = oGraph.ChartData.ChartDataCellFactory

Dim oChartSeriesEx As ChartSeriesEx

Dim oPoints As ChartPointCollectionEx

Dim oPoint As ChartPointEx

oChartSeriesEx = oGraph.ChartData.Series(iDataLabelCol - 1)

oPoints = oChartSeriesEx.Points

oPoint = oPoints(iCompanyPosition)

Hi Andrew,


I have tried to observe the requirement shared by you and like to share that the sample code shared below allows you to set the independent color for particular series point. If this is what you are looking for? If no, then please share the desired output presentation and I will try to help you further in this regard.

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

ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.StackedColumn, 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 = seriesCollection[1];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Yellow;

series = seriesCollection[2];

ChartPointEx point = new ChartPointEx(series);
point.Index = 0;
point.Format.Fill.FillType = FillTypeEx.Solid;
point.Format.Fill.SolidFillColor.Color = Color.DeepSkyBlue;
series.Points.Add(point);

point = new ChartPointEx(series);
point.Index = 1;
point.Format.Fill.FillType = FillTypeEx.Solid;
point.Format.Fill.SolidFillColor.Color = Color.LightGreen;
series.Points.Add(point);

point = new ChartPointEx(series);
point.Index = 2;
point.Format.Fill.FillType = FillTypeEx.Solid;
point.Format.Fill.SolidFillColor.Color = Color.Orange;
series.Points.Add(point);

point = new ChartPointEx(series);
point.Index = 3;
point.Format.Fill.FillType = FillTypeEx.Solid;
point.Format.Fill.SolidFillColor.Color = Color.OrangeRed;
series.Points.Add(point);

series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Cyan;

pres.Write(@“C:\ChartExample.pptx”);


Please also share the sample application used on your end for expedite investigation.

Many Thanks,

Howdy,

That's actually really useful for something else I need to do, but I was talking about setting the data label for a single point, not setting the look of the actual point.

Cheers

Andy

Hi Andy,


I am assuming that by data point you are actually meaning the series label values. I have generated the following sample code for your convenience. In the sample, I have set the custom values to series labels and thier properties are changed as well. Please share, if I may help you further in this regard. If you need something else then please share the requirements in the form of example so that I may help you exactly what is required.

public static void setIndividuelLabelProps()
{
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 10, 10, 500, 500);

chart.ChartData.Series.RemoveAt(1);
chart.ChartData.Series.RemoveAt(1);

ChartSeriesEx series = chart.ChartData.Series[0];

//Adding Series label and its properties
DataLabelEx label = new DataLabelEx(series);
label.Id = 0;
label.TextFrame.Text = “Firs val”;
PortionFormatEx porFormat=label.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
porFormat.FontBold = NullableBool.True;
porFormat.FontHeight = 12;
porFormat.FillFormat.FillType = FillTypeEx.Solid;
porFormat.FillFormat.SolidFillColor.Color = Color.Red;

series.Labels.Add(label);

label = new DataLabelEx(series);
label.Id = 1;
label.TextFrame.Text = “2nd val”;
porFormat = label.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
porFormat.FontBold = NullableBool.True;
porFormat.FontHeight = 14;
porFormat.FillFormat.FillType = FillTypeEx.Solid;
porFormat.FillFormat.SolidFillColor.Color = Color.Green;

series.Labels.Add(label);



label = new DataLabelEx(series);
label.Id = 2;
label.TextFrame.Text = “3rd val”;
porFormat = label.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
porFormat.FontBold = NullableBool.True;
porFormat.FontHeight = 18;
porFormat.FillFormat.FillType = FillTypeEx.Solid;
porFormat.FillFormat.SolidFillColor.Color = Color.Yellow;

series.Labels.Add(label);

label = new DataLabelEx(series);
label.Id = 3;
label.TextFrame.Text = “4th val”;
porFormat = label.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
porFormat.FontBold = NullableBool.True;
porFormat.FontHeight = 20;
porFormat.FillFormat.FillType = FillTypeEx.Solid;
porFormat.FillFormat.SolidFillColor.Color = Color.Blue;

series.Labels.Add(label);


series.Labels.ShowValue = false ;
series.Labels.ShowSeriesName = false;
series.Labels.ShowCategoryName = false;
series.Labels.LinkedSource = false;

//Saving Presentation
pres.Write(“D:\Aspose Data\SeriesLabelValue.pptx”);



}

Many Thanks,

Hi,

Not quite what I am after. My template attached as Just350.pptx already has data and data labels associated with each point.

Your example shows how to add a data label from scratch I want to reference an existing one..

How do I use DataLabelsEx and DataLabelEx to reference one of my two series?

In my example (Just350.pptx) I have two series ('Median' and '0').

I have been playing around with referencing the series with:

Dim oChartSeriesEx1 As ChartSeriesEx = oGraph.ChartData.Series(0)

Dim oChartSeriesEx2 As ChartSeriesEx = oGraph.ChartData.Series(1)

Dim lbl As DataLabelEx

Dim lbls As DataLabelsEx

But what next to just get a reference to say the 4th point in oChartSeriesEx1

I have to say that you really need to add some simple examples into your documentation I found it virtually useless in many case.

Cheers

Andy

Hi Andy,


I have observed the requirement and regret to share that Aspose.Slides returns 0 series labels count if the series labels are added by default to show the series values. This seems to be an issue and I have created a ticket with ID SLIDESNET-34017 to further investigate and resolve the issue.

However, I have shared the workaround approach to tackle the issue and you may use the following code to serve the purpose of exactly what is required. I have also shared the generated presentation for reference as well.

public static void TestLabelWoraround()
{
String path = @“D:\Aspose Data”;
PresentationEx pres = new PresentationEx(path + “Just350.pptx”);
SlideEx slide = pres.Slides[0];
foreach (ShapeEx shape in slide.Shapes)
{
if (shape is ChartEx)
{
ChartEx chart = (ChartEx)shape;

ChartSeriesEx series = chart.ChartData.Series[0];
series.Labels.ShowValue = false;

int cnt = series.Labels.Count;
DataLabelEx label=null;
for (int i = 0; i < series.Values.Count;i++ )
{
//Adding Series label and its properties
label = new DataLabelEx(series);
label.Id = i;
label.TextFrame.Text = series.Values[i].Value.ToString();
series.Labels.Add(label);
}
DataLabelEx lab=series.Labels[3];

PortionFormatEx porFormat = lab.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
porFormat.FontBold = NullableBool.True;
porFormat.FontHeight = 24;
porFormat.FillFormat.FillType = FillTypeEx.Solid;
porFormat.FillFormat.SolidFillColor.Color = Color.Red;


}
}
pres.Write(path + “Just350_2.pptx”);
}


Please share, if I may help you further in this regard.

Many Thanks,

Hi,

Seems like a bit of a bug to me that you can't reference an existing label in a series! I tried the approach you suggested and I got it to work.

But I've now got a serious issue as a result. The problem is that if I actually add a label, with the last line of my code: oChartSeries.Labels.Add(label)

The resulting pptx file crashes when you open it and try and save it! If I comment out that last line (i.e. it doesn't do anything to that chart) it's fine.

Here's my code and I have added my generated file:

Dim oChartCategoryCollection As ChartCategoryExCollection = oGraph.ChartData.Categories

Dim iPos As Integer

iPos = 4

Dim CatValue As ChartCategoryEx

CatValue = oChartCategoryCollection(iPos)

Dim Val As Object

Val = CatValue.ChartDataCell.Value

Dim oChartSeries As ChartSeriesEx

oChartSeries = oGraph.ChartData.Series(1)

Dim label As New DataLabelEx(oChartSeries)

label.TextFrame.Text = Val.ToString

label.Id = iPos

oChartSeries.Labels.Add(label)

Hi Andy,


I have observed the scenario shared and regret to share that unfortunately this is an issue. It has already been identified in Aspose.Slides for .NET 7.x.x series and have been added with ID SLIDESNET-33996 in our issue tracking system for resolution. I have raised the priority of the issue to High as well so that it may be scheduled for resolution earlier. I will share the feedback with you in this regard as soon as the issue will be resolved.

We are very sorry for your inconvenience,

Hi,

Thank you for the update. I need some sort of timescale on this, because the work I am doing is an evaluation of your product and this is problem is a complete show stopper as it means we cannot use your product as we have a need to set individual datalabels.

There is a lot of interest in this solution in our company (Thomson Reuters) but without this being fixed we cannot buy it.

Regards

Andy

Hi Andy,


Thanks for your growing interest in our product. I like to share that I have already raised the priority of the issue and our development team will schedule it soon for investigation. With priority set to High, I am hopeful that it will be resolved soon. Hopefully in upcoming or next release. I will update you further as soon as information will be passed on to me by our development team.

Many Thanks,

Howdy,

That's great, but how often do you do releases? In the sense of when is the next release or the one after that?

Is it every few weeks or months or years? If it's likely to be fixed soon I can contnue with my proof of concept but if I am going to have to wait six months we have an issue.

Kind regards

Andy

Hi Andy,


We have a monthly product release cycle and we tend to roll out a new release by the end of the month. Some time the product release may get delayed owing to any technical hindrances.

Many Thanks,

Hi Mudassir ,

That's great I can live with that sort of timescale - assuming this bug can be fixed of course, so keep me posted!

So I'm going to continue with my POC. Which means I have another question about labels.

1. How do I put a line around my data labels (see my example file attached), to do it manually I clicked on the datalabel, went to the Format menu and selected Shape outline.

2. How do I set my label position to be Centre, Below. When I run my code by default it adds the label to the right in line with the point.

Kind regards

Andy

Hi Andy,


I have observed the requirements shared by you where you need to set the border line around any category axis label. Actually, your requirement has two parts. First is that you need to access any particular category axis label and then secondly setting the border line around it. I regret to share that both features are currently unavailable in Aspose.Slides. You can set the properties of entire labels in chart category axis for default labels created using chart creation.

I have added an issue with ID SLIDESNET-34021 as new feature request to provide support for accessing the particular category axis label. A separate issue with ID SLIDESNET-34022 as new feature has been created to provide support for setting the border line around the desired category axis label. During my testing, I have observed one more issue on my end. I.e., when setting the font related properties for the chart category axis labels in default chart, the font related properties worked. But since in your presentation, the chart category axis labels are appearing as separate entity, hence the font related properties are not being applied. I have created an issue with ID SLIDESNET-34023 to further investigate and resolve the issue. This thread has been linked with the issues so that you may be automatically notified once the features will be available and issues will resolved.

We are sorry for your inconvenience,

Hi Mudassir,

Oh dear that's not good; seems the data label implementation is not complete. But are you sure because you are talking about Category axis labels - it's impossible to set the individual category labels even manually in PowerPoint, I am only ever setting individual Series datalabels.

OK how do I set the position of the whole label series then to being Centred then? When I create a datalabels they come in my default as aligned right?

Kind regards

Andy

Hi Andy,


Thanks for your feedback and I am sorry for the fact that I made a small mistake while mixing series labels displaying categories name with category axis labels. So, SLIDESNET-34021 is no more needed and is closed. However, I have still observed the issue while setting border around the series labels and the issue SLIDESNET-34022 status has been modified to a bug. The following code must work for you when setting the border around the label. I have also shared how to set the position of labels as well for your kind reference.


public static void TestLabelWoraround2()
{
String path = @“D:\Aspose Data”;
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
{
{
ChartEx chart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 20, 20, 500, 500);

ChartSeriesEx series = chart.ChartData.Series[0];
series.Labels.ShowValue = false;

int cnt = series.Labels.Count;
DataLabelEx label=null;

for (int i = 0; i < series.Values.Count;i++ )
{
//Adding Series label and its properties
label = new DataLabelEx(series);
label.Id = i;
label.TextFrame.Text = series.Values[i].Value.ToString();
//label.Position = LegendDataLabelPositionEx.Bottom;
series.Labels.Add(label);
}
DataLabelEx lab=series.Labels[3];

PortionFormatEx porFormat = lab.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
porFormat.FontBold = NullableBool.True;
porFormat.FontHeight = 24;
porFormat.FillFormat.FillType = FillTypeEx.Solid;
porFormat.FillFormat.SolidFillColor.Color = Color.Red;
//Setting the labels borders
lab.Format.Line.FillFormat.FillType = FillTypeEx.Solid;
lab.Format.Line.FillFormat.SolidFillColor.Color = Color.Blue;
lab.Format.Line.Width = 3;
series.Labels.Format.Line.Width = 3.0;
series.Labels.Format.Line.FillFormat.FillType=FillTypeEx.Solid;
series.Labels.Format.Line.FillFormat.SolidFillColor.Color = Color.Brown;
//Setting the label positions
series.Labels.Position = LegendDataLabelPositionEx.OutsideEnd;
}
}
pres.Write(path + “Just350_2.pptx”);
}

Please also observe Label.png. Can you please share how you have added the series labels on the category axis. I have tried to achieve the same in PowerPoint and have failed to do so. I will appreciate your help in this regard.

Many Thanks,

Howdy

The trick is to create a series that just has a bunch of '0' as the items in it. Then you switch off the plotting of a point, but switch on the datalabels, because the series is all 0 the points appear on the bottom of the axis. Then you just set the label position as below and centre. This is done because of the inability to set individual Categories labels.

SO the two things that are important to me and that you have set as a high priority is that crash on Save I reported and the access of existing series datalabels (the reason for this is that I want the colours, size, format to have been set manually by the user as in some cases we have multiple series with different colours and you won't want all the labels the same colour).

Cheers

Andy

Hi Andy,


Thanks for sharing the trick. As far as the presentation corruption issue is concerned, I like to share that we are working over it on a priority basis. It has been scheduled for investigation during Week 08/2013. We will share the further information related to the issue as soon as it will be shared by our development team.

Many Thanks,

Hi Mudassir,

That's great news, thanks for letting me know.

I've been having a play with data labels and the code below allows me to create and set an individual label's property.

Apart from the LineFormat bit which is just ignored.

Kind regards

Andy

label.Id = iPos

label.Position = LegendDataLabelPositionEx.Bottom

Dim LineFormat As LineFormatEx = label.Format.Line

LineFormat.FillFormat.FillType = FillTypeEx.Solid

LineFormat.FillFormat.SolidFillColor.Color = Color.Blue

LineFormat.Width = 3

Dim porFormat As PortionFormatEx = label.TextFrame.Paragraphs(0).Portions(0).PortionFormat

porFormat.FontBold = NullableBool.True

porFormat.FontHeight = 15

porFormat.FillFormat.FillType = FillTypeEx.Solid

porFormat.FillFormat.SolidFillColor.Color = Color.Red

oChartSeries.Labels.Add(label)

Hi Andy,


That is really appreciable that you are getting the grasp over the API. Please share if I may be of any further help to you in this regard.

Many Thanks,