legend with checkbox style

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

legend with checkbox style

Post by Neelam » Thu Mar 04, 2010 10:36 am

Hi
I have a legend with checkbox style. I am showing 3 series in the chart, so there are 3 legend items with names series1,series2 and series 3. Each has one checkbox with it. If i click on legend item 's checkbox of series1, then by default it dissapears the series 1 curve on the chart. Now I want that If i click on legend item 's checkbox of series1, then lt SHOULD dissapears curves of Series 2 and series3 also along with series 1.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: legend with checkbox style

Post by Yeray » Thu Mar 04, 2010 10:54 am

Hi shikha,

I think you could do something like this:

Code: Select all

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

            for (int i = 0; i < 3; i++)
            {
                new Steema.TeeChart.Styles.Line(tChart1.Chart);
                tChart1[i].FillSampleValues();                
            }

            tChart1.Legend.CheckBoxes = true;            
            tChart1.ClickLegend += new MouseEventHandler(tChart1_ClickLegend);
        }

        void tChart1_ClickLegend(object sender, MouseEventArgs e)
        {
            if (tChart1.Legend.Clicked(e.X, e.Y) == 0)
            {
                tChart1[1].Active = false;
                tChart1[2].Active = false;
            }
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: legend with checkbox style

Post by Neelam » Thu Mar 04, 2010 11:35 am

Great .. just wanted to know what exactly is meaning of this line so that i understand the logic used in code-
if (tChart1.Legend.Clicked(e.X, e.Y) == 0)

and what if i want to do similar thing at clicking of series 2 ie - Now I want that If i click on legend item 's checkbox of series2, then lt SHOULD dissapears curves of Series 1 and series3 also along with series 2.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: legend with checkbox style

Post by Yeray » Thu Mar 04, 2010 12:53 pm

Hi shikha,

As the legend clicked method says, it "Returns the index of the clicked Legend Point". So, when the first item is clicked it returns a "0", when the second item is clicked it returns a "1",...
Are you trying to hide all the series when anyone is hidden?

Code: Select all

        void tChart1_ClickLegend(object sender, MouseEventArgs e)
        {
            int itemClicked = tChart1.Legend.Clicked(e.X, e.Y);
            if (tChart1[itemClicked].Active == false)
            {
                for (int i = 0; i < tChart1.Series.Count; i++)
                {
                    tChart1[i].Active = false;
                }
            }
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: legend with checkbox style

Post by Neelam » Wed Mar 10, 2010 11:29 am

Great..thanks... No i m not trying to hide s series when one is hidden but something similar... I can see that with the code you gave me i can achieve taht BUT when i tried it, there is one issue i am facing..

The issue is-
I have some of the series that i am not showing in legend but i am showing all series in chart.
So the below code does not work ,as if suppose there are total 5 series and 3rd and 4th are hidden in legend (showinlegend=false), and so the legend shows 1,2,5 series in legend. Now if user clicks 5th legend checkbox and goes to the code below- itemClicked will be 3 instead of 5 based on the code logic and so the code will not work. Please give generic code as its not fixed which series will not be shown in legend. Bottomline- I need TChart1.Legend.Clicked(e.X, e.Y)
based on series shown in legend(showinlegend=true). Many thanks!!


Private Sub tChart1_ClickLegend(ByVal sender As Object, ByVal e As MouseEventArgs)
'If tChart1.Legend.Clicked(e.X, e.Y) = 0 Then
' tChart1(1).Active = False
' tChart1(2).Active = False
'End If

Dim itemClicked As Integer = TChart1.Legend.Clicked(e.X, e.Y)



If TChart1(itemClicked).Active = False Then
For i As Integer = 0 To TChart1.Series.Count - 1
TChart1(i).Active = False
Next
End If
End Sub

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: legend with checkbox style

Post by Yeray » Wed Mar 10, 2010 4:40 pm

Hi shikha,

So, you have some series shown in legend and some not. And the problem is to identify which one is clicked in the legend because the legend clicked method gives you the index of the clicked item regardless on the total number of series in the chart. Here is how you could do it:

Code: Select all

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

            for (int i = 0; i < 5; i++)
            {
                new Steema.TeeChart.Styles.Line(tChart1.Chart);
                tChart1[i].FillSampleValues();
            }

            tChart1[2].ShowInLegend = false;
            tChart1[3].ShowInLegend = false;

            tChart1.Legend.CheckBoxes = true;
            tChart1.ClickLegend += new MouseEventHandler(tChart1_ClickLegend);
        }

        void tChart1_ClickLegend(object sender, MouseEventArgs e)
        {
            int tmpIndex = -1;
            int ClickedItem = tChart1.Legend.Clicked(e.X, e.Y);
            for (int i = 0; i < tChart1.Series.Count; i++)
            {                
                if (tChart1[i].ShowInLegend) tmpIndex++;
                if (tmpIndex == ClickedItem)
                {
                    tmpIndex = i;
                    break;
                }
            }
            
            MessageBox.Show(tChart1[tmpIndex].Title + " action");           
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Neelam
Advanced
Posts: 193
Joined: Fri Jun 08, 2007 12:00 am

Re: legend with checkbox style

Post by Neelam » Thu Mar 11, 2010 1:07 pm

EXCELLENT!!..It worked PERFECTLY, the way i wanted!!... MANY MANY THANKS!!!!

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: legend with checkbox style

Post by Yeray » Thu Mar 11, 2010 1:11 pm

Hi shikha,

You're welcome!!! :D
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply