Page 1 of 1
Modifying Series in TDBChart
Posted: Tue Jan 15, 2008 9:23 am
by 9236719
Hello,
I use Teechart Pro 7.12 VCL and I have a TDBChart connected to a DB.
If I want to display the values of the DB for example in p.u. I have to divide each y-value by a certain constant.
How can I do this?
thanks + regards
Reinhard
Posted: Tue Jan 15, 2008 9:56 am
by narcis
Hi Reinhard,
Sorry but I don't understand what are you trying to achieve exactly. You could try doing something like the code below after populating your series.
Code: Select all
for i:=0 to Series1.Count-1 do
begin
Series1.YValue[i] := Series1.YValue[i] / MyConst;
end;
If that's not what you are looking for please give us some more details about your requirement.
Thanks in advance.
Posted: Tue Jan 15, 2008 11:41 am
by 9236719
Hi Narcis,
the fact is, that my series depend on a DataSource.
The DataSource could be a TADODataSet (SQL), so I do not have direct access to the series values after refreshing it with CheckDataSource.
I just want to apply the constant just before displaying the y-values.
Regards, Reinhard
Posted: Wed Jan 23, 2008 4:03 pm
by Pep
Hi Reinhard,
what about using the OnBeforeDrawValues event :
Code: Select all
procedure TForm1.Series1BeforeDrawValues(Sender: TObject);
var i : integer;
begin
for i:=0 to Series1.Count do
Series1.YValue[i] := Series1.YValue[i] - (Series1.YValue[i] / 2);
end;
?
Another way would be to add the data values directly to your series by iterating through your Dataset by using the AddXY method. This way you will be able to add the modified data values too.
Posted: Thu Jan 24, 2008 7:00 pm
by 9047589
Hi, Pep!
What you suggested is a recursive scheme.
Don't you think such approach will result in dissapearing the whole series after several iterations with, say, zoom-unzoom?
Posted: Fri Jan 25, 2008 9:49 am
by narcis
Hi Alexander,
No, I don't think so if axes are set to automatic as they would automatically set their scales according to series values.
Posted: Fri Jan 25, 2008 10:27 am
by 9047589
Hi, NarcĂs!
I meant
Posted: Fri Jan 25, 2008 11:16 am
by narcis
Hi Alexander,
Yes, that's what I understood as well. However, if you divide all series points by the same ratio the ratio between them will be preserved too. So, if instead of being from 0 to 100 it's from 0 to 0.0001, axes will be automatically scaled to represent this.
Moreover, if Reinhard only wants this to happen the very first time the series are plotted then he could use a boolean flag to determine whether this code should be executed or not.
Posted: Fri Jan 25, 2008 11:57 am
by 9047589
narcis wrote:Hi Alexander,
Yes, that's what I understood as well. However, if you divide all series points by the same ratio the ratio between them will be preserved too. So, if instead of being from 0 to 100 it's from 0 to 0.0001, axes will be automatically scaled to represent this.
Moreover, if Reinhard only wants this to happen the very first time the series are plotted then he could use a boolean flag to determine whether this code should be executed or not.
Thanks Narcis, I appreciate your valuable comments.
In't it possible to use OnAfterAdd event for scaling Series?
Posted: Fri Jan 25, 2008 12:56 pm
by narcis
Hi Alexander,
OnAfterAdd event doesn't work, you could do that in the chart's OnAfterDraw event, for example:
Code: Select all
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i : integer;
begin
for i:=0 to Series1.Count do
Series1.YValue[i] := Series1.YValue[i] - (Series1.YValue[i] / 2);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.Draw;
end;