Page 1 of 1

Change of Recordsource stops the Smoothed line

Posted: Thu Jul 05, 2012 2:45 pm
by 16657737
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

Re: Change of Recordsource stops the Smoothed line

Posted: Fri Jul 06, 2012 7:25 am
by yeray
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.

Re: Change of Recordsource stops the Smoothed line

Posted: Mon Jul 16, 2012 1:03 pm
by 16657737
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

Re: Change of Recordsource stops the Smoothed line

Posted: Mon Jul 16, 2012 3:41 pm
by yeray
Hi Ben,

We are getting a "System error in date query expression 'dtDate = #28/abr/2012#'". Could you please check the project?

Re: Change of Recordsource stops the Smoothed line

Posted: Mon Jul 16, 2012 3:50 pm
by 16657737
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

Re: Change of Recordsource stops the Smoothed line

Posted: Tue Jul 17, 2012 5:19 pm
by yeray
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

Re: Change of Recordsource stops the Smoothed line

Posted: Wed Jul 18, 2012 9:13 am
by 16657737
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?

Re: Change of Recordsource stops the Smoothed line

Posted: Wed Jul 18, 2012 3:14 pm
by yeray
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.

Re: Change of Recordsource stops the Smoothed line

Posted: Thu Jul 19, 2012 8:39 am
by 16657737
Brilliant.

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

Re: Change of Recordsource stops the Smoothed line

Posted: Thu Jul 19, 2012 10:32 am
by yeray
Hi Ben,

Glad to hear it! :)