Chart Legend: Checkboxes not Clickable

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
buchi
Newbie
Newbie
Posts: 14
Joined: Thu Jan 05, 2006 12:00 am

Chart Legend: Checkboxes not Clickable

Post by buchi » Thu Sep 09, 2010 11:17 am

Hi

Toggling the visibility of certain series by using the corresponding checkboxes of the legend seems to fail under some special circumstances.

Imagine a series gets (invisibly) painted even beyond the chart axes. If such a line crosses the location of a checkbox, this checkbox is no longer clickable. Please take a look at the beautiful "TeePaperChart" attached to this post for further clarification.

Unfortunately we stick at version 2.0.2987.19069 as our reporting component has some issues with nested controls and just does not display the charts when using newer TeeCharts versions.

May I ask you for your assistance to find a workarround to get those checkboxes working under all circumstances? We would higly apprechiate your help.

Thank you very much

Manuel
Attachments
20100909174713_00001.jpg
20100909174713_00001.jpg (16.85 KiB) Viewed 8442 times

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

Re: Chart Legend: Checkboxes not Clickable

Post by Yeray » Fri Sep 10, 2010 1:36 pm

Hi Manuel,

I've tried to reproduce the problem with the following code but I can't.
Note that I'm drawing a line at AfterDraw event over the series line to see if the hidden part of the series passes for the legend checkbox.

Code: Select all

public Form1()
        {
            InitializeComponent();

            CreateChart();
            InitializeChart();
        }

        private Steema.TeeChart.TChart tChart1;
        private void CreateChart()
        {
            this.Width = 900;
            this.Height = 600;

            Steema.TeeChart.Commander chartController1 = new Steema.TeeChart.Commander();
            chartController1.Dock = DockStyle.Top;

            tChart1 = new Steema.TeeChart.TChart();
            tChart1.Dock = DockStyle.Fill;

            chartController1.Chart = tChart1;

            this.Controls.Add(tChart1);
            this.Controls.Add(chartController1);
        }


        private Steema.TeeChart.Styles.Line series;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            new Steema.TeeChart.Styles.Line(tChart1.Chart);
            new Steema.TeeChart.Styles.Line(tChart1.Chart);

            series = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            series.LinePen.Width = 3;
            series.Add(10);
            series.Add(0);
            series.Add(10);
            series.Add(0);

            tChart1.Axes.Bottom.SetMinMax(0, 3);
            tChart1.Axes.Left.SetMinMax(1.5, 10);

            tChart1.Panel.MarginBottom = 7;
            tChart1.Legend.CheckBoxes = true;
            tChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
            tChart1.Legend.CustomPosition = true;
            tChart1.Legend.Left = 330;
            tChart1.Legend.Top = 510;

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (tChart1[1].Active)
            {
                g.Pen.Width = 1;
                g.Pen.Color = Color.Black;
                g.Line(series.CalcXPos(0), series.CalcYPos(0), series.CalcXPos(1), series.CalcYPos(1));
                g.Line(series.CalcXPos(1), series.CalcYPos(1), series.CalcXPos(2), series.CalcYPos(2));
            }
        }
I couldn't reproduce it either in TeeChart v4 nor v2.
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

buchi
Newbie
Newbie
Posts: 14
Joined: Thu Jan 05, 2006 12:00 am

Re: Chart Legend: Checkboxes not Clickable

Post by buchi » Mon Sep 13, 2010 6:20 am

Hi Yeray
Thank you for your message. Please find attached a small sample project which easily shows the issue described in my first post.
Best regards,
Manuel
Attachments
TeeChartDemo.zip
(45.13 KiB) Downloaded 325 times

buchi
Newbie
Newbie
Posts: 14
Joined: Thu Jan 05, 2006 12:00 am

Re: Chart Legend: Checkboxes not Clickable

Post by buchi » Mon Sep 13, 2010 7:45 am

Hi Yeray

I am quite surprised that your example is working. I looked at the differences and figured out that two additional conditions must be met:
  • There must be a handler for the ClickSeries event of the chart
  • Legend.CustomPosition must be false
Please find the modified code below.

Best regards,
Manuel

Code: Select all

        public Form2()
        {
            InitializeComponent();

            CreateChart();
            InitializeChart();
        }

        private Steema.TeeChart.TChart tChart1;
        private void CreateChart()
        {
            this.Width = 900;
            this.Height = 600;

            Steema.TeeChart.Commander chartController1 = new Steema.TeeChart.Commander();
            chartController1.Dock = DockStyle.Top;

            tChart1 = new Steema.TeeChart.TChart();
            tChart1.Dock = DockStyle.Fill;

            chartController1.Chart = tChart1;

            this.Controls.Add(tChart1);
            this.Controls.Add(chartController1);
        }


        private Steema.TeeChart.Styles.Line series;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            new Steema.TeeChart.Styles.Line(tChart1.Chart);
            new Steema.TeeChart.Styles.Line(tChart1.Chart);

            series = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            series.LinePen.Width = 3;
            series.Add(10);
            series.Add(0);
            series.Add(10);
            series.Add(0);

            tChart1.Axes.Bottom.SetMinMax(0, 3);
            tChart1.Axes.Left.SetMinMax(1.5, 10);

            tChart1.Panel.MarginBottom = 7;
            tChart1.Legend.CheckBoxes = true;
            tChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
            //tChart1.Legend.CustomPosition = true;
            //tChart1.Legend.Left = 330;
            //tChart1.Legend.Top = 510;

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);

            tChart1.ClickSeries += new Steema.TeeChart.TChart.SeriesEventHandler(tChart1_ClickSeries);
        }

        void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
        {
            Console.WriteLine("Series clicked");
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (tChart1[1].Active)
            {
                g.Pen.Width = 1;
                g.Pen.Color = Color.Black;
                g.Line(series.CalcXPos(0), series.CalcYPos(0), series.CalcXPos(1), series.CalcYPos(1));
                g.Line(series.CalcXPos(1), series.CalcYPos(1), series.CalcXPos(2), series.CalcYPos(2));
            }
        }

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart Legend: Checkboxes not Clickable

Post by Sandra » Mon Sep 13, 2010 9:49 am

Hello Manuel,

I have checked yeray's code again, and work well using either version 4 or version 2. Can you please explain us because previous code doesn't work fine for you? Because we can so we try to find a solution for your problem.


Thanks,
Best Regards,
Sandra Pazos / 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

buchi
Newbie
Newbie
Posts: 14
Joined: Thu Jan 05, 2006 12:00 am

Re: Chart Legend: Checkboxes not Clickable

Post by buchi » Mon Sep 13, 2010 10:39 am

Hi Sandra

Yeray's code is working fine. The problem is that we do not want to position the legend manually and that we need the series click event. As soon as you change those two things in Yeray's code it will expose the same issue as my code currently has. Please try out either the modified version of Yeray's code or the sample project I have provided earlier.

Thank you

Best regards,
Manuel

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

Re: Chart Legend: Checkboxes not Clickable

Post by Yeray » Mon Sep 13, 2010 1:49 pm

Hi Manuel,

I could reproduce the problem now. It seems that the ClickSeries event may conflict with the legend checkboxes in the situation you described (the part of the series out of the chart rect would be over the legend). I've added it to the defect list to be fixed in future releases (TF02015147).

In the meanwhile you could try using MouseMove event in combination with series' click method instead of the ClickSeries event.
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

buchi
Newbie
Newbie
Posts: 14
Joined: Thu Jan 05, 2006 12:00 am

Re: Chart Legend: Checkboxes not Clickable

Post by buchi » Tue Sep 14, 2010 3:51 am

Hi Yeray

Unfortunately, the series click event causes the same problem.
Based on the chart's MouseClick event and the Clicked method of the series it seems possible to implement a workarround:

Code: Select all

        void tChart1_MouseClick(object sender, MouseEventArgs e)
        {
            Rectangle chartR = tChart1.Chart.ChartRect;
            if (chartR.Contains(e.Location))
            {
                for (int i = tChart1.Series.Count - 1; i >= 0 ; i--)
                {
                    if (tChart1[i].Visible && tChart1[i].Clicked(e.X, e.Y) != -1)
                    {
                        Debug.WriteLine("Series " + i + " clicked");
                        break;
                    }
                }
            }
        }
Best regards,
Manuel

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart Legend: Checkboxes not Clickable

Post by Sandra » Tue Sep 14, 2010 11:49 am

Hello buchi,

Thanks for your information. I have checked your workaround and it seems that works fine here too :).

Thanks,
Best Regards,
Sandra Pazos / 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

Post Reply