Page 1 of 2

Extra legend tool

Posted: Mon Apr 06, 2009 11:26 am
by 10545622
Hi,

How is it possible to add a custom symbol in an Extra legend tool ?
I use LegendStyle := lsGroups and i would like to draw a colored square between the check box and the text of the group name.
I didn't find when the Symbol.OnDraw event is fired.

Best regards

Posted: Mon Apr 06, 2009 2:20 pm
by yeray
Hi stsl,

Yes, I'm afraid that there is no event for customizing the ExtraLegendTool symbol. But you always can draw custom rectangles directly to the canvas at OnAfterDraw event or where you are customizing your tool.

Posted: Mon Apr 06, 2009 2:30 pm
by 10545622
Are you sure that it's only on the extra legend tool ?
With the normal legend, it's not possible to have symbols when we use lsGroups.
I don't know why i purchased TeeChart because i have to draw myself everything.


Regards

Posted: Mon Apr 06, 2009 2:52 pm
by 10545622
Your are wrong, it's also possible to add rectangle in an extralegend but only when we are in lsSeries mode.
Please, this behaviour is very important for me and (and very urgent) and i have no time to find a workaround for this bug (for me, it's a bug,
and when i use TeeChart, i spend 60% of my time to bypass bugs and strange things).

Posted: Mon Apr 06, 2009 3:36 pm
by yeray
Hi stsl,

Excuse me if I haven't been enough clear. I meant that the event OnDraw for symbol legend only seems to work for the normal legend, not for this tool. And I've added it to the wish list to be fixed asap (TV52014060).

So, for the normal legend it would be easy to draw the custom symbols with this event (you can see the demo at All Features/Miscellaneous/Legend/Symbol OnDraw).

Note that for a legend where each item represents a point (with a concrete color) or a series (with a concrete color) it's easy to determine the symbol to draw. But having a group of series, there is not a clear unique solution (or we haven't determined yet) on which symbol has to be drawn.

Posted: Mon Apr 06, 2009 4:37 pm
by 10545622
I have to use an extra legend tool and not a normal legend (see my different post about the legend and the solution that you suggested for me in the past).

Note :
I know that you can't determine wich color we have to use for a group but i know that i would like to see in my legend (not a color in my case...)

I am afraid about your "ASAP" criteria. I am waiting a patch for a very important bug since 2005.

Posted: Tue Apr 07, 2009 8:21 am
by yeray
Hi stsl,
stsl wrote:I am waiting a patch for a very important bug since 2005.
Could you please tell us the number of the bug or the forum thread where this bug was discussed and we'll see its state?

We understand that, in the customer side, some of you have important problems that demand immediate intervention, but without any doubt, you'll understand that we also have to value other aspects such as the number of customers affected, if there is a workaround or not, the percentage of the component that is affected, the relation cost/benefit of the implementation,...

Posted: Tue Apr 07, 2009 11:04 am
by 10545622
Summary of my post, about a very critical bug (null values are different than 0 values) :

Posted: 02 Nov 2005 18:35 Post subject: Functions, period range and data leak

and your response

Posted: 07 Apr 2008 10:13 Post subject: Reply with quote
Hi stsl,

I've added the feature request to the wish list (TV52012945) to be reviewed and, if possible, enhanced in further releases. This may be quite a sensible issue as implementing it as you request may break existing clients code.

Also notice that we don't provide support for changes to the source code but you are free to implement the necessary customizations to fit your needs.
_________________
Best Regards
Yeray Alonso


Best regards

Posted: Tue Apr 07, 2009 11:49 am
by yeray
Hi stsl,

Please, see my answer in the according forum thread.

Posted: Thu Apr 30, 2009 8:05 am
by 10545622
When did you plan to fix this bug ? I hope in the 8.05 release.....

Posted: Thu Apr 30, 2009 10:27 am
by narcis
Hi stsl,

Here's an update on the status of the issues discussed on this thread:

TV52014060: I've checked this already works fine here using something as the code below. Can you please check if this works fine for you?

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues();
  ChartTool1.Legend.Symbol.OnDraw:=LegendDraw;
end;

procedure TForm1.LegendDraw(Sender: TObject; Series:TChartSeries;
                            ValueIndex:Integer; R:TRect);
var Flag : TBitmap;
begin
  Flag:=TBitmap.Create;  // create flag bitmap
  try
    Dec(R.Top,3);
    Inc(R.Bottom,3);

    if ValueIndex mod 2 = 0 then
      Flag.LoadFromFile('C:\temp\TeeCopy.bmp')
    else
      Flag.LoadFromFile('C:\temp\TeeDepth.bmp');

    with Chart1.Canvas do
    begin
      StretchDraw(R,Flag);  // draw image to legend

      // draw border
      if Chart1.Legend.Symbol.Pen.Visible then
      begin
        Brush.Style:=bsClear;
        AssignVisiblePen(Chart1.Legend.Symbol.Pen);
        Rectangle(R,0);
      end;
    end;

  finally
    Flag.Free;  // destroy bitmap
  end;
end;
TV52012945: We don't consider this being a bug but a feature request, which is very specific. In my opinion Yeray suggested you several options to achieve what you request using existing TeeChart features. Given all those circumstances it's most unlikely that it's implemented in v8. We don't have an estimate date for this being implemented either.

Posted: Thu Apr 30, 2009 10:57 am
by 10545622
TV52014060 :
Did you use LegendStyle := lsGroups ?


TV52012945 :
For me it's a bug because the function generates wrong values in the graph (0 instead null values).

Best regards

Posted: Thu Apr 30, 2009 11:38 am
by narcis
Hi stsl,
V52014060 :
Did you use LegendStyle := lsGroups ?
Ok, the problem here is that series groups don't have symbol. So if you want to use symbols there you could use dummy series for that purpose, for example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
  Chart1.Legend.Visible:=false;
  Series1.FillSampleValues();
  ChartTool1.Legend.Symbol.OnDraw:=LegendDraw;

  for i:=0 to Chart1.SeriesCount -1 do
    Chart1[i].ShowInLegend:=false;

  for j:=0 to Chart1.SeriesGroups.Count-1 do
  begin
    Chart1.AddSeries(TChartSeries.Create(self));
    Chart1[Chart1.SeriesCount-1].ShowInLegend:=true;
    Chart1[Chart1.SeriesCount-1].Title:=Chart1.SeriesGroups[j].Name;
  end;

  ChartTool1.Series:=Chart1[Chart1.SeriesCount-1];
  ChartTool1.Legend.LegendStyle:=lsSeries;
end;

procedure TForm1.LegendDraw(Sender: TObject; Series:TChartSeries;
                            ValueIndex:Integer; R:TRect);
var Flag : TBitmap;
begin
  Flag:=TBitmap.Create;  // create flag bitmap
  try
    Dec(R.Top,3);
    Inc(R.Bottom,3);

    Flag.LoadFromFile('C:\root\TeeChartVCL\Sources8\TeeCopy.bmp');
{    if ValueIndex mod 2 = 0 then
      Flag.LoadFromFile('C:\root\TeeChartVCL\Sources8\TeeCopy.bmp')
    else
      Flag.LoadFromFile('C:\root\TeeChartVCL\Sources8\TeeDepth.bmp');
}
    with Chart1.Canvas do
    begin
      StretchDraw(R,Flag);  // draw image to legend

      // draw border
      if Chart1.Legend.Symbol.Pen.Visible then
      begin
        Brush.Style:=bsClear;
        AssignVisiblePen(Chart1.Legend.Symbol.Pen);
        Rectangle(R,0);
      end;
    end;

  finally
    Flag.Free;  // destroy bitmap
  end;
end;

Posted: Thu Apr 30, 2009 12:23 pm
by 10545622
But i need a normal legend with series (not the dummies) and an extra legend with groups (dummies) and check box to disable one or more groups of other series. Is-it possible to do that ? I think that with dummies series it will be complicated.

Why did you disable the OnDrawLegend event when we have lsGroups ? There is no logical reason...

Posted: Thu Apr 30, 2009 1:47 pm
by narcis
Hi stsl,
But i need a normal legend with series (not the dummies) and an extra legend with groups (dummies) and check box to disable one or more groups of other series. Is-it possible to do that ? I think that with dummies series it will be complicated.
Yes, I'm afraid this would be complicated.
Why did you disable the OnDrawLegend event when we have lsGroups ? There is no logical reason...
In my opinion the reason it is pretty simple, since series groups don't have symbols for the legend they can't fire the OnDraw event. This is already on the wish-list to be considered for inclusion in future releases.