Page 1 of 1

Need some help for a simple task!!!

Posted: Tue Nov 13, 2012 8:37 am
by 10046032
Hello all,

I am completely stack with this so I need a fresh look from someone else!!! I created this chart, works as I want to but it looks like I cannot hide one name group, for example I need the user to be able to show/hide Name1 or Name2 etc. Any help please !!!!

Re: Need some help for a simple task!!!

Posted: Tue Nov 13, 2012 3:24 pm
by yeray
Hi Johnnix,

Could you please clarify if you want to hide just the "Name2" text, or also the bars above it?

Re: Need some help for a simple task!!!

Posted: Wed Nov 14, 2012 7:36 am
by 10046032
Hello,

I need to hide both label and bars :)

Regards

Re: Need some help for a simple task!!!

Posted: Wed Nov 14, 2012 8:44 am
by yeray
Hi Johnnix,

Then, I'd work with null points. Known the ValueIndex to hide, you can loop all your series and set as null:

Code: Select all

  for i:=0 to Chart1.SeriesCount-1 do
    Chart1[i].SetNull(ValueIndex);

Re: Need some help for a simple task!!!

Posted: Wed Nov 14, 2012 9:03 am
by yeray
Hi again,

In addition to the above, when I tried the following code, where I have 5 TBarSeries with 5 values each and I want to hide the ValueIndex=2:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i, j, ValueIndex: Integer;
begin
  Chart1.View3D:=false;

  for i:=0 to 4 do
  begin
    with Chart1.AddSeries(TBarSeries) do
    begin
      FillSampleValues(5);
      Marks.Visible:=false;

      for j:=0 to Chart1[i].Count-1 do
        Chart1[i].Labels.Labels[j]:='Name'+IntToStr(j+1);
    end;
  end;

  ValueIndex:=2;  //ValueIndex to hide
  for i:=0 to Chart1.SeriesCount-1 do
    Chart1[i].SetNull(ValueIndex);
end;
I've seen the bars with ValueIndex=2 are correctly hidden, but not the bottom axis label.
However, you can always hide those labels in the bottom axis with no visible value associated:

Code: Select all

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
var i: Integer;
begin
  if (Sender=Chart1.Axes.Bottom) and (ValueIndex>-1) then
    for i:=0 to Chart1.SeriesCount-1 do
      if Chart1[i].IsNull(ValueIndex) then
      begin
        if i=Chart1.SeriesCount-1 then
          LabelText:='';
      end
      else
        exit;
end;
And the above seems to work fine for me here.

Re: Need some help for a simple task!!!

Posted: Thu Nov 15, 2012 7:41 am
by 10046032
Hello Yeray,

Thank you very much for the prompt reply, I will give it a try !!!

Kindest regards