Page 1 of 1

Checking count of items in series after zoom

Posted: Wed Apr 23, 2008 8:28 am
by 9349520
Hello

i have problem
i would like to show marks but in special conditions.
When chart is in 100% zoom i would like automatically hide marks because there is to much points and showing marks is not useful. So my problem is to check number of showing points in series and if it less than X i would like to set marks to visible. Is there any way to do it?

thanks in advance

Posted: Wed Apr 23, 2008 9:40 am
by narcis
Hi guzial,

You can do something like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(1000);
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  SetMarksVisible(Series1);
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  SetMarksVisible(Series1);
end;

procedure TForm1.SetMarksVisible(Series: TChartSeries);
begin
  Chart1.Draw;
  Series.Marks.Visible:=not (Series.VisibleCount>20);
end;

Posted: Thu Apr 24, 2008 6:55 am
by 9349520
what about TGanttSeries ?

Posted: Mon Apr 28, 2008 9:06 am
by yeray
Hi guzial,

Yes, there seems to be a bug for Gantt series because VisibleCount doesn't seem to return the correct value. I've added it to the wish list to be fixed in further releases (TV52013013). But here you have a workaround that works fine for me here:

Code: Select all

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  SetMarksVisible(Series1);
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  SetMarksVisible(Series1);
end;

procedure TForm1.SetMarksVisible(Series: TChartSeries);
var i, nInRange: Integer;
begin
  Chart1.Draw;
  nInRange := 0;
  for i:=0 to Series.Count-1 do
  begin
    if (Series.YValue[i] > Chart1.Axes.Left.Minimum) and (Series.YValue[i] < Chart1.Axes.Left.Maximum) then
      nInRange := nInRange+1;
  end;

  Series.Marks.Visible := not (nInRange > 10);
  Series.Marks.Clip := true;
end;