Change of Recordsource stops the Smoothed line

TeeChart for ActiveX, COM and ASP
Post Reply
JobyLeigh
Newbie
Newbie
Posts: 7
Joined: Tue Nov 02, 2010 12:00 am

Change of Recordsource stops the Smoothed line

Post by JobyLeigh » Thu Jul 05, 2012 2:45 pm

I have a screen whereby the user selects a date, which creates a new recordset (from Access) grabbing only the records with the specified date. When this recordset is passed to the Series Line for a second time and any time after that, the Series line is no longer Smoothed.

Here is the code to setup the graph during the FormLoad event (there are 7 days to display, so seven Series Lines) :
For i = 0 To 6
TChart1.Series(i).XValues.ValueSource = "dtTime"
TChart1.Series(i).YValues.ValueSource = "AAMean"

TChart1.Series(i).Pen.Width = LineThickness
TChart1.Series(i).asLine.Smoothed = 1
Next i

Here is the code to Redraw the graph...
For i = 0 To 6
strSQL = "SELECT * FROM Analysis WHERE dtDate = #" & Format(DateAdd("d", i, ShowDate), "dd/mmm/yyyy") & "# ORDER BY dtDate, dtTime"

Call dbRecordSet.Open(strSQL)

If dbRecordSet.RecordCount = 0 Then
TChart1.Series(i).Active = False
Else
TChart1.Series(i).Active = True
TChart1.Series(i).DataSource = dbRecordSet
End If
dbRecordSet.Close
Next i

As I say, the series line, when drawn for the first time, is smooth. However, when the recordset is refreshed with new SQL, the line is redrawn and it is not smoothed.
Is there any reason for this or is there a better way for me to deal with making a line smooth?

Thanks in advance.
Ben

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Change of Recordsource stops the Smoothed line

Post by Yeray » Fri Jul 06, 2012 7:25 am

Hi Ben,

Have you tried cleaning the series before refreshing and reassigning the recordset again?
If it doesn't help, you could try using a second series to draw the smoothed line and try to see it better. The first series could still be the linked to the recordset, refreshing it when needed. Then, the second series could use the first series as datasource, and use a Smoothing function as in the example at "All Features\Welcome !\Functions\Extended\Smoothing SpLine" in the features demo application included with the installation.

If you still have problems with it, don't hesitate to let us know, and please try to arrange a simple example project we can run as-is to reproduce the problem here.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JobyLeigh
Newbie
Newbie
Posts: 7
Joined: Tue Nov 02, 2010 12:00 am

Re: Change of Recordsource stops the Smoothed line

Post by JobyLeigh » Mon Jul 16, 2012 1:03 pm

Thank you for the reply.
I have included an example project which displays a smoothed line when the project is first loaded, but a change of date reloads the line and removes the smoothness. I would be thinking that as the line has been dictated as smooth, it should stay as such (unless I have unknowingly changed it when I refresh the datasource).

Alternatively, I might be accessing and refreshing the datasource in an incorrect manner and there might be a better way of doing it that does not cause the line to appear jagged after a refresh.

Thanks in advance.
Ben
Attachments
Graph Smoothed Project.zip
Example Project
(54.65 KiB) Downloaded 889 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Change of Recordsource stops the Smoothed line

Post by Yeray » Mon Jul 16, 2012 3:41 pm

Hi Ben,

We are getting a "System error in date query expression 'dtDate = #28/abr/2012#'". Could you please check the project?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JobyLeigh
Newbie
Newbie
Posts: 7
Joined: Tue Nov 02, 2010 12:00 am

Re: Change of Recordsource stops the Smoothed line

Post by JobyLeigh » Mon Jul 16, 2012 3:50 pm

Apologies for that. I have removed the formatting of the dtDate and have advanced the dates within the data so it should successfully work (there was no error here so I can only assume this was the issue)
Kind regards,
Ben
Attachments
Graph Smoothed Project2.zip
Updated
(53.58 KiB) Downloaded 851 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Change of Recordsource stops the Smoothed line

Post by Yeray » Tue Jul 17, 2012 5:19 pm

Hi Ben,

When the Smoothed propery is being set, an internal Line series with a Smoothing function is created. However, when the "parent" series is updated, these internal series and function associated aren't updated.
You have two ways to achieve the same:

- Way #1: Create the internal series and function manually and update it manually.
To do it, change the for loop in your Form_Load() for this, to add the extra series:

Code: Select all

Private Sub Form_Load()
'...
        Dim i As Integer
        For i = 0 To 3
            .Series(i).Pen.Width = 2
            '.Series(i).asLine.Smoothed = 1
            .AddSeries scLine
        Next
'...
End Sub
And at the end of yor comDate_Change() method, before the call to RefreshData, add the following for loop:

Code: Select all

Private Sub comDate_Change()
'...
        For i = 0 To 3
            .Series(4 + i).SetFunction tfSmoothing
            .Series(4 + i).DataSource = .Series(i)
            .Series(4 + i).Pen.Width = .Series(i).Pen.Width
            .Series(4 + i).Color = .Series(i).Color
            .Series(i).Active = False
        Next
'...
End Sub
- Way #2: Remove all the series and add them again each time at the begining of your comDate_Change method adding the following:

Code: Select all

Private Sub comDate_Change()

    TChart1.RemoveAllSeries
    Dim i As Integer
    With TChart1
        For i = 0 To 3
            .AddSeries scLine
        Next
    End With

    '...
End Sub
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JobyLeigh
Newbie
Newbie
Posts: 7
Joined: Tue Nov 02, 2010 12:00 am

Re: Change of Recordsource stops the Smoothed line

Post by JobyLeigh » Wed Jul 18, 2012 9:13 am

Yeray,
Thanks for your assistance. I have successfully managed to keep my lines smooth!

However, and this is tempermental in the test project I am uploading so I hope you are able to replicate at your end (but does it all the time in my live project), Bottom axis resets, so it no longer appears as a Time, but as a value between 0 and 1.
When I trace through the code, it draws the straight lines as per normal. When it gets to the new For loop to assign the line thickness and Smoothness, the line gets redrawn as smooth, but the bottom axis switches from the specified times set up on the graph settings, and changes to 0 to 1.

Any ideas?
Attachments
Graph Smoothed Project3.zip
(53.79 KiB) Downloaded 884 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Change of Recordsource stops the Smoothed line

Post by Yeray » Wed Jul 18, 2012 3:14 pm

Hi Ben,

Extending what I said before:
Yeray wrote:When the Smoothed propery is being set, an internal Line series with a Smoothing function is created.
But these internal lines aren't inheriting the XValues.DateTime status from its "source" series.
However, you can still force it manually addig this at the end of your comDate_Change() method, before the call to RefreshData:

Code: Select all

Private Sub comDate_Change()
'...
        TChart1.Environment.InternalRepaint

        For i = 0 To TChart1.SeriesCount - 1
            .Series(i).XValues.DateTime = True
        Next
'...
End Sub
Note you have to call InternalRepaint to let TeeChart create the Smoothing functions.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JobyLeigh
Newbie
Newbie
Posts: 7
Joined: Tue Nov 02, 2010 12:00 am

Re: Change of Recordsource stops the Smoothed line

Post by JobyLeigh » Thu Jul 19, 2012 8:39 am

Brilliant.

Thanks ever so much for your help Yeray. All working and all sorted!

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Change of Recordsource stops the Smoothed line

Post by Yeray » Thu Jul 19, 2012 10:32 am

Hi Ben,

Glad to hear it! :)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply