An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Thank you for reaching out.
The approach you are using to get the minimum value and adjust the Y values is correct. The idea is to find the smallest Y value and subtract it from all items so that the new minimum becomes 0.
However, getting negative values usually means the minimum value is not being taken from the same data that is being updated, or the data is changing before applying the calculation.
To make this work correctly, calculate the minimum value once from the same collection and then use that value for all updates, like this:
var values1 = values.ToArray();
var minY = values1.Min(v => v.Y);
for (int i = 0; i < values1.Length; i++)
{
values1[i].Y = values1[i].Y - minY;
}
After this, the smallest Y value will always be 0, and other values will be adjusted correctly.
If negative values still appear, it indicates the source data may be changing before or during this operation.
Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer". So that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.