The idea is create a Custom control public class CustomChart : Chart where automatically it will get the Rectangle (X,Y,Widht,Height) of the each label of the DataPoints and check for the collision with the Y Axis maximum coord.

The first idea I've implemented is using pixel relative to the Control rather than using Values due to the labels have to be 90º. My problem is that I can't figure out how to get those Coordinates for the DataPoints label (X,Y,Width,Height) and for the Y Axis. If that intersection would be true the chart should reescalate (without modify the Font Size).
I've implemented an event OnMouseMove to check the coordinates with the mouse, where it's pretty easy gets those coordinates.
Here is the code of the custom Class:
namespace WinformTest_InterseccionLabelVSTitle {
public class CustomChart : Chart
{
private Dictionary<DataPoint, RectangleF> labelPositions = new Dictionary<DataPoint, RectangleF>();
private ToolTip toolTip;
public CustomChart()
{
toolTip = new ToolTip();
toolTip.AutoPopDelay = 1000;
}
protected override void OnPostPaint(ChartPaintEventArgs e)
{
base.OnPostPaint(e);
if (e.ChartElement is Series series)
{
//Get area de grafico
ChartArea chartArea = this.ChartAreas[series.ChartArea];
RectangleF plotArea = chartArea.InnerPlotPosition.ToRectangleF();
foreach (DataPoint point in series.Points)
{
// Obtiene las coordenadas X e Y del datapoint
double xValue = point.XValue;
double yValue = point.YValues[0]; // En caso de tener múltiples YValues, puedes acceder a ellos según su índice
// Get the position of the label. IT DOESN'T SEEMS TO GET THE SAME HAS THE COORDINATES WITH THE MOUSE HIT TEST.
Point labelPosition1 = Point.Empty;
labelPosition1.X = (int)chartArea.AxisX.ValueToPixelPosition(xValue);
labelPosition1.Y = (int)chartArea.AxisY.ValueToPixelPosition(xValue);
Point labelPosition2 = Point.Empty;
labelPosition2.X = (int)chartArea.AxisX.ValueToPixelPosition(yValue);
labelPosition2.Y = (int)chartArea.AxisY.ValueToPixelPosition(yValue);
}
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
// Get the mouse coordinates
//double xValue = ChartAreas[0].AxisX.PixelPositionToValue(e.X);
//double yValue = ChartAreas[0].AxisY.PixelPositionToValue(e.Y);
double xValue = e.X;
double yValue = e.Y;
// Display the coordinates in the tooltip
toolTip.SetToolTip(this, $"X: {xValue}, Y: {yValue}");
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
Chart chart = (Chart)this;
HitTestResult hitTestResult = chart.HitTest(e.X, e.Y);
if (hitTestResult.ChartElementType == ChartElementType.DataPointLabel)
{
// DataPoint was clicked
DataPoint dataPoint = hitTestResult.Series.Points[hitTestResult.PointIndex];
double x = e.X;
double y = e.Y;
MessageBox.Show($"DataPoint clicked,X:{x},Y:{y}");
}
else if (hitTestResult.ChartElementType == ChartElementType.LegendItem)
{
// LegendItem was clicked
LegendItem legendItem = hitTestResult.Object as LegendItem;
MessageBox.Show("LegendItem clicked");
}
else if (hitTestResult.ChartElementType == ChartElementType.AxisLabels)
{
// AxisLabels were clicked
Axis axis = hitTestResult.Object as Axis;
double x = e.X;
double y = e.Y;
MessageBox.Show($"AxisLabels clicked,X:{x},Y:{y}");
}
}
}
Thanks for your help and also any other approach would be welcome but it has to be automatic and the label has to be in 90º ;