We're creating PowerPoint presentations containing, among other things, line charts. In some cases we need to draw an arrow (or other shape) that points to a specific point on the chart, given the point's (x,y)
values in the chart.
To do this, we need the absolute position of the chart point, relative to the slide's top-left corner.
Currently we're using Interop to calculate the dimensions of the chart's plot area, from which we can then calculate the absolute position of a given chart point, as shown below:
// The chart point's X- and Y values
double x = ... ;
double y = ... ;
PowerPoint.Shape shape = ... ;
PowerPoint.Chart chart = shape.Chart;
double plotAreaLeft = shape.Left + chart.ChartArea.Left + chart.PlotArea.InsideLeft;
double plotAreaTop = shape.Top + chart.ChartArea.Top + chart.PlotArea.InsideTop;
double plotAreaWidth = chart.PlotArea.InsideWidth;
double plotAreaHeight = chart.PlotArea.InsideHeight;
// Calculating the range of X- and Y values
double xMin = ... ;
double xRange = ... ;
double yMin = ... ;
double yRange = ... ;
// Calculating the exact position of the point
double left = plotAreaLeft + (x - xMin) * plotAreaWidth / xRange;
double top = plotAreaTop + (y - yMin) * plotAreaHeight / yRange;
Now this works fine, but we're in the process of moving the application to a server, and switching from Interop to OpenXml for creating the presentations.
The problem is that the dimensions of the PlotArea are not fixed, but dynamically calculated by PowerPoint, and this calculation seems to be depending on a lot of factors including labels, font, legend, and users manually changing the position of the PlotArea. We're trying to reverse-engineer this calculation, but so far we haven't been able to come up with a solution that hits the target every time.
We have tried commercial frameworks, such as Aspose.Slides, but they also seem to have the same problem (the functionality is listed in their API, but the values are never calculated - they always have a value of NaN
).
My question is thus: Does anybody have any help or resources we can use, or any experiences with this problem?
Thanks in advance.