private void AddStatisticsAnnotations(ChartArea chartArea, int channelIndex)
{
    RemoveExistingAnnotations(channelIndex);
    
    float chartAreaX = chartArea.Position.X; 
    float chartAreaY = chartArea.Position.Y; 
    float chartAreaWidth = chartArea.Position.Width; 
    float chartAreaHeight = chartArea.Position.Height; 
    
    float offsetX = 10f;  
    float offsetY = 5f;  
    
    float posX = chartAreaX + offsetX;
    float posY = chartAreaY + offsetY;
    
    Color textColor = _channelColors[channelIndex % _channelColors.Length];
    
    string annotationText = $"Max: - V\nAvg: - V\nMin: - V";
    TextAnnotation annotation = new TextAnnotation
    {
        Name = $"StatsAnnotation{channelIndex}",
        Text = annotationText,
        ForeColor = textColor,
        X = posX,
        Y = posY,
        Alignment = ContentAlignment.TopLeft,
        ClipToChartArea = chartArea.Name,
        IsSizeAlwaysRelative = true, 
        Font = new Font("Arial", 10)  
    };
    chartWaveform.Annotations.Add(annotation);
    
}
private void RemoveExistingAnnotations(int channelIndex)
{       
    
    string annotationName = $"StatsAnnotation{channelIndex}";
    var annotation = chartWaveform.Annotations.FindByName(annotationName);
    if (annotation != null)
    {
        chartWaveform.Annotations.Remove(annotation);
    }
}
private void UpdateChannelStatistics(int channelIndex, List<ushort> values)
{
    if (values == null || values.Count == 0) return;
    
    double maxAdc = values[0];
    double minAdc = values[0];
    double sumAdc = 0;
    foreach (var value in values)
    {
        if (value > maxAdc) maxAdc = value;
        if (value < minAdc) minAdc = value;
        sumAdc += value;
    }
    double avgAdc = sumAdc / values.Count;
    
    double maxAdcValue = Math.Pow(2, adcBit) - 1;
    double maxVoltage = vref / 1000.0;
    double maxV = (maxAdc / maxAdcValue) * maxVoltage;
    double minV = (minAdc / maxAdcValue) * maxVoltage;
    double avgV = (avgAdc / maxAdcValue) * maxVoltage;
    
    UpdateStatsAnnotationText(channelIndex, maxV, avgV, minV);
}
private void UpdateStatsAnnotationText(int channelIndex, double maxV, double avgV, double minV)
{
    string annotationName = $"StatsAnnotation{channelIndex}";
    var annotation = chartWaveform.Annotations.FindByName(annotationName) as TextAnnotation;
    if (annotation != null)
    {
        annotation.Text = $"Max: {maxV:F3}V\nAvg: {avgV:F3}V\nMin: {minV:F3}V";
    }
}  
AddStatisticsAnnotations(chartWaveform.ChartAreas[ch], ch);
UpdateChannelStatistics(ch, channelValues[ch]);