OnGetLegendText

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
AMS
Newbie
Newbie
Posts: 24
Joined: Wed Mar 31, 2004 5:00 am
Location: South Africa
Contact:

OnGetLegendText

Post by AMS » Mon Aug 22, 2005 7:15 am

Hi all,

I have two bar series added to my chart, Series1 and Series2, ShowInLegend = true by default and legend checkbox enabled.

If the user un-checks Series2 from the legend checkbox and even thought the series is not visible on the chart, if the moves mouse over the chart where the series did have a point, the OnGetLegendText event fires with the properties from the invisible series item and the mark is displayed. Surely a hidden series should not show mark tips?

Got any solutions?

John.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Aug 22, 2005 8:40 am

Hi John,

I haven't been able to reproduce what you report using latest TeeChart version available (v7.04). Which TeeChart version are you using? Could you please send us an example we can run "as-is" to reproduce the problem here? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

AMS
Newbie
Newbie
Posts: 24
Joined: Wed Mar 31, 2004 5:00 am
Location: South Africa
Contact:

Post by AMS » Thu Aug 25, 2005 5:27 am

Hi Narcis,
I have duplicated the problem using version 7.05. I am now not sure whether it is a TChart bug, rather it may be an implementation problem. Anyway, please take a look.

Here is the scenario:
- Draw 3 TLineSeries, with Legend->Checkbox->Visible.
- Move the mouse over the series points and the custom tool tip object shall display the constructed text on mouse move.
- Take note of a specific point XY location.
- Then unchecked the series, whose location you have taken note of, and run the mouse over that point.
- You will see that the ToolTip is still displayed. I dont want the tooltip to be displayed when the series is uncheked.

Code: Select all

class TfrmMain : public TForm
{
__published:	// IDE-managed Components
  TChart *Chart;
  TChartEditor *ChartEditor;
  TPopupMenu *PopupMenu;
  TMenuItem *ChartProperties;
  void __fastcall FormShow(TObject *Sender);
  void __fastcall ChartPropertiesClick(TObject *Sender);
  void __fastcall FormDestroy(TObject *Sender);
  void __fastcall ChartMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
private:	// User declarations
  void __fastcall MarkToolGetText(TMarksTipTool* Sender, AnsiString &Text);

  TList         *ToolTips;
  AnsiString    SeriesName;
  TMarksTipTool *SeriesToolTipPtr;
public:		// User declarations
  __fastcall TfrmMain(TComponent* Owner);
};

__fastcall TfrmMain::TfrmMain(TComponent* Owner)
  : TForm(Owner)
{
  SeriesToolTipPtr              = new TMarksTipTool(Owner);
  SeriesToolTipPtr->ParentChart = Chart;
  SeriesToolTipPtr->MouseAction = mtmMove;
  SeriesToolTipPtr->Style       = smsValue;
  SeriesToolTipPtr->OnGetText   = MarkToolGetText;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::FormShow(TObject *Sender)
{
  TLineSeries *ptrToLineSeries;

  Chart->Legend->CheckBoxes = true;

  for( int i=0; i < 3; i++ )
  {
    ptrToLineSeries = new TLineSeries(Chart);
    ptrToLineSeries->Title = "Series " + AnsiString(i);

    ptrToLineSeries->FillSampleValues(20);
    ptrToLineSeries->ShowInLegend = true;
    ptrToLineSeries->Pointer->Visible = true;

    Chart->AddSeries( ptrToLineSeries );
  }

}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ChartPropertiesClick(TObject *Sender)
{
  ChartEditor->Execute();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::ChartMouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
  int ser_click = 0;

  SeriesName = "";
  for( int i=0; i < Chart->SeriesCount(); i++ )
  {
    if( (Chart->SeriesList->Items[i]->ClassNameIs("TLineSeries")) ||
        (Chart->SeriesList->Items[i]->ClassNameIs("TFastLineSeries")) )
    {

      ser_click = Chart->SeriesList->Items[i]->Clicked(X, Y);

      if( ser_click >= 0 )
      {

        SeriesName = "Series Name: " + Chart->SeriesList->Items[i]->Title;

      } // if( ser_click >= 0 )

    }

  } // for( int i=0; i < Chart->SeriesCount(); i++ )

}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::MarkToolGetText(TMarksTipTool* Sender, AnsiString &Text)
{
  SeriesName += "\rSeries Value: ";
  Text.Insert(SeriesName, 0);
}
Thanks in advance for the help,
Regards John.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Aug 25, 2005 12:19 pm

Hi John,

Thanks for the code. I've been able to reproduce this problem and added the issue to our defect list to be considered for future releases. A workaround can be only filling the text to display if clicked series is visible, otherwise put a blank string on it. You will get the clicked series index at the MouseMove event.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

AMS
Newbie
Newbie
Posts: 24
Joined: Wed Mar 31, 2004 5:00 am
Location: South Africa
Contact:

Post by AMS » Fri Aug 26, 2005 6:08 am

Thanks Narcis,

I have included the fix here so that others may imlement the work around.

Code: Select all

class TfrmMain : public TForm
{
__published:	// IDE-managed Components
  TChart *Chart;
  TChartEditor *ChartEditor;
  TPopupMenu *PopupMenu;
  TMenuItem *ChartProperties;
  void __fastcall FormShow(TObject *Sender);
  void __fastcall ChartPropertiesClick(TObject *Sender);
  void __fastcall ChartMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
private:	// User declarations
  void __fastcall MarkToolGetText(TMarksTipTool* Sender, AnsiString &Text);

  AnsiString    SeriesName;
  TMarksTipTool *SeriesToolTipPtr;
  bool          ShowToolTip;
public:		// User declarations
  __fastcall TfrmMain(TComponent* Owner);
};

__fastcall TfrmMain::TfrmMain(TComponent* Owner)
  : TForm(Owner)
{
  SeriesToolTipPtr              = new TMarksTipTool(Owner);
  SeriesToolTipPtr->ParentChart = Chart;
  SeriesToolTipPtr->MouseAction = mtmMove;
  SeriesToolTipPtr->Style       = smsValue;
  SeriesToolTipPtr->OnGetText   = MarkToolGetText;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::FormShow(TObject *Sender)
{
  TLineSeries *ptrToLineSeries;

  Chart->Legend->CheckBoxes = true;

  for( int i=0; i < 3; i++ )
  {
    ptrToLineSeries = new TLineSeries(Chart);
    ptrToLineSeries->Title = "Series " + AnsiString(i);

    ptrToLineSeries->FillSampleValues(20);
    ptrToLineSeries->ShowInLegend = true;
    ptrToLineSeries->Pointer->Visible = true;

    Chart->AddSeries( ptrToLineSeries );
  }

}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ChartPropertiesClick(TObject *Sender)
{
  ChartEditor->Execute();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::ChartMouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
  int ser_click = 0;

  SeriesName = "";
  for( int i=0; i < Chart->SeriesCount(); i++ )
  {
    if( (Chart->SeriesList->Items[i]->ClassNameIs("TLineSeries")) ||
        (Chart->SeriesList->Items[i]->ClassNameIs("TFastLineSeries")) )
    {

      if( Chart->SeriesList->Items[i]->Visible == true )
      {
        ser_click = Chart->SeriesList->Items[i]->Clicked(X, Y);
      }
      else
      {
        ser_click = -1;
      }

      if( ser_click >= 0 )
      {

        ShowToolTip = true;
        SeriesName = "Series Name: " + Chart->SeriesList->Items[i]->Title;

      } // if( ser_click >= 0 )

    }

  } // for( int i=0; i < Chart->SeriesCount(); i++ )

}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::MarkToolGetText(TMarksTipTool* Sender, AnsiString &Text)
{
  if( ShowToolTip )
  {
    SeriesName += "\rSeries Value: ";
    Text.Insert(SeriesName, 0);
    ShowToolTip = false;
  }
  else
  {
    Text = "";
  }
}
Regards, John.

Post Reply