Page 1 of 1

Selecting a series to chart

Posted: Mon Jun 26, 2006 2:22 pm
by 9641475
I have 4 series that I am currently charting on a single line chart but since they vary in scale greatly the lines are nearly flat and are of little to no use. I would like to allow the user to select which series to chart and have the option to select all. I am wondering if there is a way to use hotspots or something to handle this within the chart, possibly in the legend. The other option is to remove the legend and handle it with a legend that I create in HTML to control the selection of series.

Any suggestions?

Posted: Mon Jun 26, 2006 2:28 pm
by narcis
Hi chiphotx,

The easiest way to achieve that is using legend checkboxes:

Code: Select all

            tChart1.Legend.CheckBoxes = true;

Posted: Mon Jun 26, 2006 2:30 pm
by 9641475
perfect, thanks

Posted: Mon Jun 26, 2006 4:02 pm
by 9641475
Are there any example or tutorials on how to handle chart events so I can capture the click of the checkbox?

Posted: Mon Jun 26, 2006 4:24 pm
by 9641475
I've got this code to handle the code but it doesn't catch the event.

Private Sub WebChart1_ClickLegend(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles WebChart1.ClickLegend
Dim SeriesIndex As Integer

SeriesIndex = WebChart1.Chart.Legend.Clicked(e.X, e.Y)
test.Text = "helo"

End Sub

Posted: Tue Jun 27, 2006 9:56 am
by narcis
Hi chiphotx,

In an ASP.NET application you can use legend checkboxes doing something like this:

Code: Select all

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace LegendCheckboxes
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected Steema.TeeChart.Web.WebChart WebChart1;
		public static MemoryStream tmpChart;
		private static int index = -1;
		private static bool flag=true;
		private static ArrayList checkedSeries;

		private void Page_Load(object sender, System.EventArgs e)
		{
			Steema.TeeChart.Chart ch1;
			if(flag) 
			{
				ch1=WebChart1.Chart;
				ch1.Legend.CheckBoxes = true;
				ch1.Series.Add(new Steema.TeeChart.Styles.Line());
				ch1.Series.Add(new Steema.TeeChart.Styles.Line());
				ch1.Series.Add(new Steema.TeeChart.Styles.Line());
				ch1.Series.Add(new Steema.TeeChart.Styles.Line());
				checkedSeries = new ArrayList();
				for (int i=0;i<ch1.Series.Count;++i) 
				{
					ch1[i].FillSampleValues();
					CheckedSeries chk	= new CheckedSeries(ch1[i].Active, i);
					checkedSeries.Add(chk);

				}
				tmpChart = new MemoryStream();
				ch1.Export.Template.Save(tmpChart);
			
				flag = false;
			}
			else 
			{
				ch1=WebChart1.Chart;
				tmpChart.Position = 0;
				ch1.Import.Template.Load(tmpChart);
			}
		}

		private void WebChart1_ClickLegend(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			index=WebChart1.Chart.Legend.Clicked(e.X,e.Y); 
			if(index != -1) 
			{
				CheckedSeries chk = (CheckedSeries)checkedSeries[index];
				chk.IsActive = !chk.IsActive;
				checkedSeries.RemoveAt(chk.Index);
				checkedSeries.Insert(chk.Index,chk); 
				Bitmap bmp = WebChart1.Chart.Bitmap();
			}
		}

		private void WebChart1_BeforeDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{
			for (int i=0;i<WebChart1.Chart.Series.Count;++i) 
			{
				CheckedSeries chk = (CheckedSeries)checkedSeries[i];
				WebChart1.Chart[i].Active = chk.IsActive;
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{   
			this.WebChart1.ClickLegend += new Steema.TeeChart.Web.WebChart.ClickEventHandler(this.WebChart1_ClickLegend);
			this.WebChart1.BeforeDraw += new Steema.TeeChart.PaintChartEventHandler(this.WebChart1_BeforeDraw);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		public struct CheckedSeries 
		{
			public CheckedSeries(bool isActive, int index) 
			{
				IsActive = isActive;
				Index = index;
			}
			public bool IsActive;
			public int Index;
		}
	}
}
You can convert C# code to VB.NET using one of the language conversors below:

http://carlosag.net/Tools/CodeTranslator/Default.aspx
http://www.kamalpatel.net/ConvertCSharp2VB.aspx

ClickLegend

Posted: Tue Mar 18, 2008 9:56 am
by 13045688
Hi Narcís,

I have tried your code but I was getting a cross (X) image box when run.
Could you please send me a complete workable source code?
I am having difficulty to enable the "click legend".

Thanks.

ClickLegend

Posted: Tue Mar 18, 2008 10:08 am
by 13045688
Hi Narcís,
I am able to get it to work now.
But there is an issue (I think I have posted it before) whereby when click on legend checkbox, hold down and release of the mouse click is considered "2 clicks".
Is this bug has been resolved?
If yes, where do I get the patch?
If not, when do we expect a solution?

Thanks.

Posted: Tue Mar 18, 2008 10:47 am
by narcis
Hi tangone,
But there is an issue (I think I have posted it before) whereby when click on legend checkbox, hold down and release of the mouse click is considered "2 clicks".
Yes, you posted this here.
Is this bug has been resolved?
No, this issue hasn't been fixed yet.
If yes, where do I get the patch?
All TeeChart maintenance releases can be downloaded at the client area.
If not, when do we expect a solution?
I'm sorry but I can't give an estimate date at the moment. For new release announcements and what's being fixed on them please be aware at this forum or subscribe to our RSS feed.

Thanks in advance.