We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to get actual position and size of Chart data label?


I can get almost all the data from a label inside a chart, however if I need to draw something (for example a circle around the data label, NOT the squared border) I need to know the position inside the chart.

However when I do something like this:

int iSerie = 1;
int iCategory = 2;

objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.X <== I get NaN
objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.Y <== I get NaN
objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.Width <== I get NaN
objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.Height <== I get NaN

objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.ActualX <== I get 0 always
objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.ActualY <== I get 0 always
objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.ActualWidth <== I get 0 always
objChart.ChartData.Series[iSerie].DataPoints[iCategory].Label.ActualHeight <== I get 0 always

I want to get the X, Y Width and Height to draw an AutoShape like this:
objChart.UserShapes.Shapes.AddAutoShape(ShapeType.Cloud, X, Y, WIDTH, HEIGHT)

Can someone help me?

Welcome to our community! Thank you for posting the query. You should recalculate the positions of chart elements to get actual values as shown below:


Documents: Chart Calculations
API Reference: IDataLabel Interface