Free Support Forum - aspose.com

How to Add datalabels at some points in line chart

Hi,

I want to add datalabel for last 3 points only in line chart.
How can I do that. Its very urgent please reply ASAP.

Thanks
Saurabh

Hi Saurabh,


Please use the code snippet given below for adding data labels to chart series items. The following example is for Stacked Column chart but you can use for your reference for line chart as well.

//create new chart
PresentationEx presColumn = new PresentationEx();
SlideEx sld = presColumn.Slides[0];
ChartEx newChart = sld.Shapes.AddChart(ChartTypeEx.StackedColumn3D, 100, 100, 550, 400);
ChartSeriesEx ser = newChart.ChartData.Series[0];

newChart.ChartTitle.Text.Text = “Sample Title”;
newChart.ChartTitle.Text.CenterText = true;
newChart.ChartTitle.Height = 20;
newChart.HasTitle = true;
//Set first series to Show Values
newChart.ChartData.Series[0].Labels.ShowValue = true;

//add new series to chart
ChartDataCellFactory fact = newChart.ChartData.ChartDataCellFactory;
int idx = newChart.ChartData.Series.Add(fact.GetCell(0, 0, 4, “NewSeries”), newChart.Type);
ser = newChart.ChartData.Series[idx];
ser.Values.Add(fact.GetCell(0, 1, 4, 5));
ser.Values.Add(fact.GetCell(0, 2, 4, 7));
ser.Values.Add(fact.GetCell(0, 3, 4, 6));
ser.Values.Add(fact.GetCell(0, 4, 4, 8));


//create custom lables for each of categories for new series

//first label will be show Category name
DataLabelEx lbl = new DataLabelEx(ser);
lbl.ShowCategoryName = true;
lbl.Id = 0;
ser.Labels.Add(lbl);

//Show series name for second label
lbl = new DataLabelEx(ser);
lbl.ShowSeriesName = true;
lbl.Id = 1;
ser.Labels.Add(lbl);

//show value for third label
lbl = new DataLabelEx(ser);
lbl.ShowValue = true;
lbl.ShowSeriesName = true;
lbl.Separator = “/”;
lbl.Id = 2;
ser.Labels.Add(lbl);

// show value and custom text
lbl = new DataLabelEx(ser);
lbl.TextFrame.Text = “My text”;
lbl.Id = 3;
ser.Labels.Add(lbl);


presColumn.Write(@“D:\Aspose Data\PresWithColumnChart.pptx”);


Thanks and Regards,