Legend tooltip

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Legend tooltip

Post by qcrnd » Mon Sep 08, 2008 6:35 am

Hi
I have a series graph and I would like to limit the size of the title of each series displayed in the legend rectangle (series.Title) so that the legend rectangle will have a size limit, However I want the full text to be available as a tooltip or something when hovering over one of the series name in the legend box.
Is it possible ?
couldnt find any reference or property that seemed associated with a tooltip.
Thanks.

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 Sep 08, 2008 7:59 am

Hi qcrnd,

Yes, you can do something like this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;

			for (int i = 0; i < 3; i++)
			{
				Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);

				bar1.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked;
				bar1.FillSampleValues();
				bar1.Title = "Series number " + i.ToString();
			}

			tChart1.GetLegendText += new Steema.TeeChart.GetLegendTextEventHandler(tChart1_GetLegendText);
			tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
		}

		void tChart1_MouseMove(object sender, MouseEventArgs e)
		{
			int index = tChart1.Legend.Clicked(e.X, e.Y);

			tChart1.Tools.Clear();

			if (index != -1)
			{
				Steema.TeeChart.Tools.Annotation annotation1 = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);

				annotation1.Text = tChart1[index].Title;
				annotation1.Shape.CustomPosition = true;
				annotation1.Shape.Left = e.X - 50;
				annotation1.Shape.Top = e.Y; 
			}
		}

		void tChart1_GetLegendText(object sender, Steema.TeeChart.GetLegendTextEventArgs e)
		{
			int index = e.Text.LastIndexOf(" ");
			e.Text = e.Text.Substring(index);
		}
Hope this helps!
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

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Post by qcrnd » Mon Sep 08, 2008 1:43 pm

HI Narcis

Thanks Alot .
This is more or less what I need. Just some issues I hope you can help me with so that it will be perfect.
1. I dont quite like the fact that the tooltip is following the mouse , is there any way I can get the tooltip to stay in one place , somewhere a little above the actual title inside the legend just like regular tooltips. I couldnt find how to get the specific title position inside the legend.
2. More important , is there any way I can set the right position of the tooltip and have the tooltip expand towards the left as must as it needs. This is becuase if the legend is aligned to the right , then sometimes there is not enough room for all the text on the right side and it is cut. In case the legend is aligned to the right I would like to set the Right position of the annotation.Shape . something like annotation.Shape.Right = e.X. I tried this but it doesnt work , it sets the the annotion at the Left side of the graph.
3. is there any way to control the background color of the annotation.

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 Sep 08, 2008 1:57 pm

Hi qcrnd,

Yes, you can do something like this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;

			for (int i = 0; i < 3; i++)
			{
				Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);

				bar1.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked;
				bar1.FillSampleValues();
				bar1.Title = "Series number " + i.ToString();
			}

			tChart1.GetLegendText += new Steema.TeeChart.GetLegendTextEventHandler(tChart1_GetLegendText);
			tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
		}

		void tChart1_MouseMove(object sender, MouseEventArgs e)
		{
			int index = tChart1.Legend.Clicked(e.X, e.Y);

			tChart1.Tools.Clear();

			if (index != -1)
			{
				Steema.TeeChart.Tools.Annotation annotation1 = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);

				annotation1.Text = tChart1[index].Title;
				annotation1.Shape.Shadow.Visible = false;
				Bitmap bmp = tChart1.Bitmap; //force chart being internally repainted so that annotation's width can be calculated
				annotation1.Shape.CustomPosition = true;				
				annotation1.Shape.Left = tChart1.Legend.Right - annotation1.Shape.Width;
				annotation1.Shape.Top = tChart1.Legend.Items[index].Top;
				annotation1.Shape.Color = Color.Lime;
			}
		}

		void tChart1_GetLegendText(object sender, Steema.TeeChart.GetLegendTextEventArgs e)
		{
			int index = e.Text.LastIndexOf(" ");
			e.Text = e.Text.Substring(index);
		}
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

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Post by qcrnd » Mon Sep 08, 2008 2:28 pm

Hi again
1 looks like we are getting closer but this doesnt compile.
Legend doesnt have an array called Items

2 Another thing I wanted to ask -
you use the line Bitmap bmp = Chart.Bitmap; to help you get the width .

wouldnt it be better to use the MeasureString to get the width.
using(Graphics g = Chart.CreateGraphics())
{
size = g.MeasureString(annotation.Text,annotation.Shape.Font.DrawingFont);
}

Thanks.

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

Post by Narcís » Tue Sep 09, 2008 7:54 am

Hi qcrnd,

1. This code compiles and works fine for me here using latest TeeChart for .NET v3 release available at the client area. Which TeeChart version are you using?

2. No because MeasureString would only give the width of the text not the width of the full annotation tool shape.
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

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Post by qcrnd » Tue Sep 09, 2008 8:46 am

Hi

we are using version 2.0.2306.26232
and Legend doesnt seem to have a member items . Can you see if there is another way to get the positition of the titles ?
Thanks.


Below is the Legend metadata we have

[ToolboxItem(false)]
public class Legend : TextShapePosition
{
public bool ColumnWidthAuto;
public int[] ColumnWidths;

public Legend(Chart c);

[Description("Defines the Legend position.")]
public LegendAlignments Alignment { get; set; }
[DefaultValue(false)]
[Description("Enables/disables the display of Legend check boxes.")]
public bool CheckBoxes { get; set; }
[Description("Changes the background color of the Legend box.")]
[DefaultValue(typeof(Color), "White")]
public Color Color { get; set; }
[DefaultValue(true)]
[Description("Legend shows only the current page items.")]
public bool CurrentPage { get; set; }
[DesignerSerializationVisibility(2)]
[Description("Pen used to draw lines separating Legend items.")]
public ChartPen DividingLines { get; }
[Description("Sets the first Legend item displayed")]
[DefaultValue(0)]
public int FirstValue { get; set; }
[DefaultValue(false)]
[Description("Sets the legend text font color to that of the Series color.")]
public bool FontSeriesColor { get; set; }
[Description("Sets number of screen pixels between Legend and Chart rectangles.")]
[DefaultValue(0)]
public int HorizMargin { get; set; }
[Description("When True, draws the Legend items in opposite direction.")]
[DefaultValue(false)]
public bool Inverted { get; set; }
[Description("Defines which items will be displayed in Chart Legend.")]
public LegendStyles LegendStyle { get; set; }
[EditorBrowsable(2)]
[Browsable(false)]
public string[] Lines { get; set; }
[Description("Max number of Legend Rows displayed in a horizontal Legend.")]
[DefaultValue(10)]
public int MaxNumRows { get; set; }
[Description("Resizes Chart rectangle to prevent overlap with Legend.")]
[DefaultValue(true)]
public bool ResizeChart { get; set; }
[DesignerSerializationVisibility(0)]
[Browsable(false)]
[Description("Determine the series used as data for the Legend entries.")]
public Series Series { get; set; }
[Description("Sets width and position of color rectangle associated to each Legend item.")]
[DesignerSerializationVisibility(2)]
public LegendSymbol Symbol { get; }
[Browsable(false)]
[Description("Use the Text property to add text to the Legend.")]
[EditorBrowsable(2)]
public string Text { get; set; }
[Description("Determines how Legend text items will be formatted.")]
public LegendTextStyles TextStyle { get; set; }
[Localizable(true)]
[DesignerSerializationVisibility(2)]
[Description("Sets the Title text and its characteristics at the top of the legend.")]
public LegendTitle Title { get; }
[DefaultValue(10)]
[Description("Specifies the Legend's top position in percent of total chart height.")]
public int TopLeftPos { get; set; }
[DesignerSerializationVisibility(0)]
[Browsable(false)]
[Description("Returns True only if the legend is left or right aligned.")]
public bool Vertical { get; }
[DefaultValue(0)]
[Description("Sets the vertical margin in pixels between Legend and Chart rectangle.")]
public int VertMargin { get; set; }
[Description("Sets vertical spacing between Legend items (pixels).")]
[DefaultValue(0)]
public int VertSpacing { get; set; }

public int Clicked(int x, int y);
protected internal bool DoMouseDown(int x, int y);
public string FormattedLegend(int seriesOrValueIndex);
public string FormattedValue(Series aSeries, int valueIndex);
public override void Paint(Graphics3D g, Rectangle rect);
}
}

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

Post by Narcís » Tue Sep 09, 2008 9:23 am

Hi qcrnd,

Thanks for the information.

First of all, please notice that there's a newer release of v2 available at the client download area.

Regarding your inquiry, I can't think of an equivalent way to do this in v2. You could set annotation's top like this:

Code: Select all

				annotation1.Shape.Top = e.X;
However, using latest v2 release I've seen that legend's clicked method always returns -1.
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

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Post by qcrnd » Tue Sep 09, 2008 10:14 am

Hi Narcis

Actually the Legend.Clicked in our code returns a correct index its just that I dont know what to do with the index to get the title position.
If there is no solution with v.2 then I will use the e.Y , its just that tooltips arent supposed to track the mouse postion.

What are the implications / risks of going from v2 to v3 ? will it require any code changes from our side ? Is it fully backwards compatible.

Thanks.

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

Post by Narcís » Tue Sep 09, 2008 10:19 am

Hi qcrnd,
If there is no solution with v.2 then I will use the e.Y , its just that tooltips arent supposed to track the mouse postion.
I'm sorry but there's no other solution I can think of at the moment.
What are the implications / risks of going from v2 to v3 ? will it require any code changes from our side ? Is it fully backwards compatible.
Backwards compatibility is something we specially care about when developing new versions. You shouldn't have much problems when porting your v2 applications to v3. You should just check that TeeChart's assemblies references are upgraded properly.

If any additional problem occurs don't hesitate to let us know.
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

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Post by qcrnd » Tue Sep 09, 2008 10:55 am

OK Thanks.

Post Reply