TickLabels.Offset does not work

Hi guys,

I am trying to add offset to my value axis ticklabel but it does not work.
The purpose would be to add space between the end of the curve and the ticklabels to display the end point value (datalabels) correctly:
image.png (12.4 KB)

Could you have a look to this piece of code:

var pathWorkbook = @“C:\Users\hormancey\OneDrive - FactSet\Documents\TestHadrienMarker.xlsx”;
var pathWorkbookNew = @“C:\Users\hormancey\OneDrive - FactSet\Documents\TestHadrienMarkerBis.xlsx”;
var wbtest = new Workbook(pathWorkbook);
Worksheet sheettest = wbtest.Worksheets[0];
Chart charttest = sheettest.Charts[0];

        //Change the color to blue for the data labels.
        charttest.ValueAxis.TickLabels.Offset = 1000;
        // charttest.ValueAxis.TickLabels.RotationAngle = 90;

        wbtest.Save(pathWorkbookNew);

TestHadrienMarker.7z (11.9 KB)

Thanks,

@hormancey,

Thanks for the sample file and screenshot.

As far I know, in MS Excel, value axis labels on charts are positioned automatically, and you cannot directly set the distance between axis labels and the chart/plot area corner/end. Could you please provide a sample Excel file with a chart where the labels are positioned at your preferred offset? We will check on how to achieve this using Aspose.Cells APIs.

I am not able to do it in excel but I thought it was possible via code:

@hormancey,

Unfortunately, if a feature is unavailable for charts in MS Excel, it will also be unavailable when using Aspose.Cells APIs.

@hormancey

TickLabels.Offset only works for the tick labels of Category (X) Axis.

It seems that Excel do not allow to change offset of the value axis.
We will update description about this API.

Thanks for your quick Reply

@hormancey
You are welcome.
If you have any questions, please feel free to contact us at any time.

If I can’t set offset, do you think I can check if my datalabels intersect the axis ticklabels and move them accordingly ?
I don’t think it is possible. I don’t see any X, Y properties for the ticklabels.
Same for the Axis…

@hormancey,

Axis tick labels and axes do not expose direct X, Y, Width and Height properties, so apparently, there is no direct way to check if the data labels overlap axis tick labels. Anyways, we will further evaluate it and get back to you.

1 Like

Hi @amjad.sahi ,
Any update about this ?
Thanks,

@hormancey,

I am afraid, we attempted to evaluate it a bit but were unable to determine the intersection successfully. If we come across any useful insights or a workaround, we will share them with you.

1 Like

Hi @hormancey
Please refer to the following code to get the x, y, width, height information of each TickLabel in the Value axis.

        Worksheet sheettest = wbtest.Worksheets[0];
        Chart charttest = sheettest.Charts[0];
        charttest.Calculate();
        foreach (TickLabelItem item in charttest.ValueAxis.TickLabels.TickLabelItems)
        {
            //in ratio of chart
            double height = item.Height;
            double width = item.Width;
            double x = item.X;
            double y = item.Y;

            //in pixel
            int heightPx = (int)(height * charttest.GetActualSize()[1]);
            int widthPx = (int)(width * charttest.GetActualSize()[0]);
            int xPx = (int)(x * charttest.GetActualSize()[0]);
            int yPx = (int)(y * charttest.GetActualSize()[1]);
        }

Thanks! Very helpfull. I will try this…

@hormancey,

You are welcome. Sure, please feel free to try the code snippet. Hopefully, it serves the intended purpose.