TeeChart.NET Jagged line and time labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Mth
Newbie
Newbie
Posts: 11
Joined: Thu Dec 30, 2021 12:00 am

TeeChart.NET Jagged line and time labels

Post by Mth » Fri Aug 30, 2024 12:44 pm

Visual Studio 2022,
.net8.0 console project,
Steema.TeeChart.NET.Pro (4.2024.7.29)

Hello,

In the example below there are two problems:
1. A line that should be smooth is jagged. Some unexpected line points are displayed.
2. Displaying values ​​as time in the bottom axis labels does not work when smoothing is turned on.

Code: Select all

using Steema.TeeChart;
using Steema.TeeChart.Styles;

var mChart = new TChart();
mChart.Aspect.View3D = false;

mChart.Header.Visible = false;
mChart.Legend.Visible = false;

Line line = new Line(mChart.Chart);
line.LinePen.Width = 2;
line.Color = System.Drawing.Color.Green;

line.Smoothed = true;
line.XValues.DateTime = true;  // Does not work when smoothing is enabled

line.Add(new DateTime(2024, 04, 30, 12, 00, 00).ToOADate(), 12.5);
line.Add(new DateTime(2024, 04, 30, 12, 00, 30).ToOADate(), 52.5);
line.Add(new DateTime(2024, 04, 30, 12, 01, 00).ToOADate(), 32.5);
line.Add(new DateTime(2024, 04, 30, 12, 01, 30).ToOADate(), 22.5);
line.Add(new DateTime(2024, 04, 30, 12, 02, 00).ToOADate(), 46.5);
line.Add(new DateTime(2024, 04, 30, 12, 02, 30).ToOADate(), 5.5);
line.Add(new DateTime(2024, 04, 30, 12, 03, 00).ToOADate(), 35.5);
line.Add(new DateTime(2024, 04, 30, 12, 03, 30).ToOADate(), 20);
line.Add(new DateTime(2024, 04, 30, 12, 04, 00).ToOADate(), 40);
line.Add(new DateTime(2024, 04, 30, 12, 04, 30).ToOADate(), 10);

mChart.Series.Add(line);

mChart.Export.Image.PNG.Width = 800;
mChart.Export.Image.PNG.Height = 400;
mChart.Export.Image.PNG.Save($"D:\\TeeChartTest\\SmoothLine.png");
SmoothLine.png
SmoothLine.png (32.43 KiB) Viewed 12624 times

Edu
Newbie
Newbie
Posts: 40
Joined: Tue Nov 28, 2023 12:00 am

Re: TeeChart.NET Jagged line and time labels

Post by Edu » Wed Sep 04, 2024 8:29 am

Hello,
Thank you for bringing these issues to our attention. We've verified the bugs, and you’re absolutely correct.
1. A line that should be smooth is jagged. Some unexpected line points are displayed.
We have found out that smoothing behaves oddly with date times that are fractions of days. We're working on fixing it.
2. Displaying values ​​as time in the bottom axis labels does not work when smoothing is turned on.
This bug has already been corrected and will be fixed in the next NuGet version. Again, thank you for your report.

In the meantime, we elaborated alternative approach to address the label issue you're experiencing.

Code: Select all

//Subscribe chart to this event
mChart.GetAxisLabel += mChart_GetAxisLabel;
mChart.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
mChart.Axes.Bottom.Increment = 2; // Increasing this value reduces the number of labels displayed

Line line;
string[] dates = new string[0];
Run code:

Code: Select all

	    // Create a collection of strings
            dates = new string[]
            {
                new DateTime(2024, 04, 30, 12, 00, 00).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 00, 30).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 01, 00).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 01, 30).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 02, 00).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 02, 30).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 03, 00).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 03, 30).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 04, 00).ToShortTimeString(),
                new DateTime(2024, 04, 30, 12, 04, 30).ToShortTimeString()
            };
            
            // Add values like this instead (using your values)
            line.Add(0, 12.5);
            line.Add(1, 52.5);
            line.Add(2, 32.5);
            line.Add(3, 22.5);
            line.Add(4, 46.5);
            line.Add(5, 5.5);
            line.Add(6, 35.5);
            line.Add(7, 20);
            line.Add(8, 40);
            line.Add(9, 10);
           
           line.Smoothed = true;

            foreach (string str in dates)
                line.Labels.Add(str);                

Code: Select all

//The event
        private static void mChart_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
        {
            if (sender == mChart.Axes.Bottom)
            {
                if (!e.LabelText.Contains('.')) //just want integer index values

                {
                    int i = Convert.ToInt32(e.LabelText);
                    e.LabelText = dates[i];
                }
                else { e.LabelText = ""; }
            }
        }
And this is how it looks like
smoothing_example.png
smoothing_example.png (44.45 KiB) Viewed 11767 times
Another alternative to application of smoothing to the series is to add a smoothing function, that uses the same calculation process, but that offers properties to modify the sensitivity. Then, optionally, the original series can be hidden from view.


I hope this workaround helps for now. I'll keep you informed when the new version is released with a fix for these issues.

Best regards,
Edu
Edu
Steema Support

Post Reply