Scolling Issue

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
sunman4008
Newbie
Newbie
Posts: 18
Joined: Tue Apr 09, 2013 12:00 am

Scolling Issue

Post by sunman4008 » Tue Apr 09, 2013 2:08 pm

Hello,

I am creating a chart based on candlestick bars for stocks. I have a problem with scrolling. I am using Teecharts. When the chart pulls up, the end the x-axis is 5/16/2000. When I click on the scroll to move to the right, the beginning of the charts start X-axis is 4/5/2001. Here are my questions:
1. Why doesn't the x-axis start date beginning with the previous X-end date?
2. What parameters control the x-axis scroll? The axis is based on date.
3. In the code, I am using the following in the candlestickscroll. I notice when I use the LastDisplayIndex it gives me the values from the chart before the scroll. How do I get the values after the chart will repaint with the new x-axis values?

Code: Select all

vMin := 9999999;
   vMax := -1;
   if CandleStickSeries.LastValueIndex > 0 then
   begin
    vMin := CandleStickSeries.Lowvalues.items[CandleStickSeries.FirstDisplayedIndex] ;
    vMax := CandleStickSeries.HighValues.items[CandleStickSeries.FirstDisplayedIndex] ;


   vCandleBarDisplayed := CandleStickSeries.VisibleCount;
   vCurrentCandleIndex := CandleStickSeries.LastDisplayedIndex;

    for I  := vCurrentCandleIndex to vCandleBarDisplayed +vCurrentCandleIndex do
    begin


   if CandleStickSeries.HighValues.Items[I] > vMax  then vMax := 
                           CandleStickSeries.HighValues.Items[I];
    if CandleStickSeries.LowValues.Items[I] < vMin then vMin := 
      CandleStickSeries.LowValues.Items[I];
    end;
   end;

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

Re: Scolling Issue

Post by Yeray » Wed Apr 10, 2013 2:26 pm

Hi,
sunman4008 wrote:When I click on the scroll to move to the right...
sunman4008 wrote:1. Why doesn't the x-axis start date beginning with the previous X-end date?
I'm not sure to understand how are you scrolling. Could you please explain what function or feature are you using for it?
sunman4008 wrote:2. What parameters control the x-axis scroll? The axis is based on date.
You can scroll the chart dragging it with the right mouse button.
You can also scroll it using buttons and calling the bottom axis SetMinMax function manually.
Or you can also use the Paging feature to scroll the chart. See the examples under "All features\Welcome !\Miscellaneous\Chart Pages" in the features demo to see examples about it.
sunman4008 wrote:3. In the code, I am using the following in the candlestickscroll. I notice when I use the LastDisplayIndex it gives me the values from the chart before the scroll. How do I get the values after the chart will repaint with the new x-axis values?
You can force a chart repaint with the Chart's Draw method and get the values after 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

sunman4008
Newbie
Newbie
Posts: 18
Joined: Tue Apr 09, 2013 12:00 am

Re: Scolling Issue

Post by sunman4008 » Wed Apr 10, 2013 3:29 pm

Hello

When I start the candlestick chart, the cursor and the scroll are at the beginning date so everything is at the far left. The end date for the first chart is 5/16/200

I then to go the scroll bar and click on the right side of it with the mouse. The chart then scrolls to the right. On the first right scroll, the beginning date is 4/5/2001. Here are my questions:

1. Why is the beginning date 4/5/2001? Should it be the end date from the first chart i.e. 5/16/2000? When you click on the scroll bar at the bottom, it should move to the right with the end date becoming the beginning date and then showing how many bars you specify in the code. It doesn't do that. There is a gap between the end date of the first screen and the beginning date on the next scroll screen.
2. In the code, I use CandleStickSeries.VisibleCount;. How does the VisibleCount get determined? it is set somewhere but I don't know where the default is. this controls the number of bars on the screen.
3. Is the funcation candlestickscroll called once the bars are redrawn after the scroll or before? I notice it gets activated before the chart is redrawn with the new scroll values.

-Mike

sunman4008
Newbie
Newbie
Posts: 18
Joined: Tue Apr 09, 2013 12:00 am

Re: Scolling Issue

Post by sunman4008 » Thu Apr 11, 2013 2:50 am

Hello,

How do you Chart's Draw method ?

-Mike

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

Re: Scolling Issue

Post by Yeray » Thu Apr 11, 2013 9:09 am

Hi Mike,
sunman4008 wrote:I then to go the scroll bar and click on the right side of it with the mouse
Ah, you are using a TChartScrollBar component, right?
I'd recommend you to use a regular TScrollBar and use its OnChange event to manually scroll your chart, calling the bottom axis SetMinMax function in that event.
sunman4008 wrote:1. Why is the beginning date 4/5/2001? Should it be the end date from the first chart i.e. 5/16/2000? When you click on the scroll bar at the bottom, it should move to the right with the end date becoming the beginning date and then showing how many bars you specify in the code. It doesn't do that. There is a gap between the end date of the first screen and the beginning date on the next scroll screen.
It could be a bug in the TChartScrollBar component. Try with the TScrollBar as indicated above.
sunman4008 wrote:2. In the code, I use CandleStickSeries.VisibleCount;. How does the VisibleCount get determined? it is set somewhere but I don't know where the default is. this controls the number of bars on the screen.
Aren't you a source code customer? Take a look at the Function TChartSeries.VisibleCount:Integer; in TeEngine.pas.
sunman4008 wrote:3. Is the funcation candlestickscroll called once the bars are redrawn after the scroll or before? I notice it gets activated before the chart is redrawn with the new scroll values.
I'm not sure to understand what do you mean with candlestickscroll function, could you please precise it?
sunman4008 wrote:How do you Chart's Draw method ?
If the TChart component is names Chart1, in delphi:

Code: Select all

Chart1.Draw;
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

sunman4008
Newbie
Newbie
Posts: 18
Joined: Tue Apr 09, 2013 12:00 am

Re: Scolling Issue

Post by sunman4008 » Thu Apr 11, 2013 5:43 pm

Hello,

If you use TScrollBar...you now have to control the X-axis movement compared to the candlestickscroll.

Is there any sample code for Tscrollbar to control the x-axis movement of a chart?


-Mike

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

Re: Scolling Issue

Post by Yeray » Fri Apr 12, 2013 8:11 am

Hi Mike,

Here it is a simple example:

Code: Select all

uses CandleCh;

var nPointsToShow: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Chart1.AddSeries(TCandleSeries).FillSampleValues;

  nPointsToShow:=10;
  ScrollBar1.Max:=Chart1[0].Count-nPointsToShow-1;
  ScrollBar1.Min:=0;
  ScrollBar1.Position:=0;

  ScrollBar1Change(Self);
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
var Min, Max: double;
begin
  Min:=Chart1[0].XValue[ScrollBar1.Position];
  Max:=Chart1[0].XValue[ScrollBar1.Position+nPointsToShow];
  Chart1.Axes.Bottom.SetMinMax(Min-0.1, Max+0.1);
end;
Another alternative, with Pages:

Code: Select all

uses CandleCh;

var nPointsToShow: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Chart1.AddSeries(TCandleSeries).FillSampleValues;

  nPointsToShow:=10;
  Chart1.Pages.MaxPointsPerPage:=nPointsToShow;

  ScrollBar1.Max:=Chart1.Pages.Count;
  ScrollBar1.Min:=1;
  ScrollBar1.Position:=1;
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  Chart1.Pages.Current:=ScrollBar1.Position;
end;
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