Event to know when a serie visible property has changed

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Event to know when a serie visible property has changed

Post by acastro » Thu Jun 12, 2014 1:49 pm

There is any event to know when a serie visible property has changed? I found legend click but if it is changed from the chartcontroller it is not fired.

Thanks

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

Re: Event to know when a serie visible property has changed

Post by Narcís » Thu Jun 12, 2014 2:14 pm

Hello wakeup,

No specific event for that specific purpose. However you can use TChart.AfterDraw event, for example:

Code: Select all

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

    private bool[] SeriesVisible;
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Legend.CheckBoxes = true;

      const int numSeries = 10;
      SeriesVisible = new bool[numSeries];

      for (int i = 0; i < numSeries; i++)
      {
        tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();
        SeriesVisible[i] = tChart1[i].Visible;
      }

      tChart1.AfterDraw += tChart1_AfterDraw;
    }

    void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
    {
      for (int i = 0; i < tChart1.Series.Count; i++)
      {
        if (SeriesVisible[i] != tChart1[i].Visible)
        {
          MessageBox.Show(tChart1[i].ToString() + ".Visible is " + tChart1[i].Visible.ToString());
          SeriesVisible[i] = tChart1[i].Visible;
        }
      }
    }
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

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Event to know when a serie visible property has changed

Post by acastro » Fri Jun 13, 2014 8:59 am

The problems is, I need to add or remove a ColorLine from the chart if a serie is visible or not. So it fires AfterDraw event and is a infinite loop....


There is another way?

Thanks

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

Re: Event to know when a serie visible property has changed

Post by Narcís » Fri Jun 13, 2014 10:27 am

Hello wakeup,

Can you please attach a simple example project we can run "as-is" to see how your project works exactly so that we can try to provide a working solution?

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

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Event to know when a serie visible property has changed

Post by acastro » Fri Jun 13, 2014 10:53 am

Please find here the example.

http://193.145.251.126/pnp/files/YJoPIk ... rances.zip

I want to run the code of the button, when the visible status of a serie has been changed, in order to show or hide also his tolerance lines.

thanks

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

Re: Event to know when a serie visible property has changed

Post by Narcís » Fri Jun 13, 2014 1:57 pm

Hello wakeup,

Thanks the example projecte. Here's the code that does what you requested:

Code: Select all

  public partial class Form1 : Form
  {
    private bool[] SeriesVisible;

    public Form1()
    {
      InitializeComponent();

      chart.Series[0].FillSampleValues();
      chart.Series[1].FillSampleValues();
      chart.Series[0].Tag = 1;
      chart.Series[1].Tag = 2;

      SeriesVisible = new bool[chart.Series.Count];

      for (int i = 0; i < chart.Series.Count; i++)
      {
        refreshTolerances(i);
        SeriesVisible[i] = chart[i].Visible;
      }

      chart.AfterDraw += chart_AfterDraw;
    }

    void chart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
    {
      for (int i = 0; i < chart.Series.Count; i++)
      {
        if (SeriesVisible[i] != chart[i].Visible)
        {
          SeriesVisible[i] = chart[i].Visible;
          refreshTolerances(i);
        }
      }
    }

    private void button1_Click(object sender, EventArgs e)
    {
      for (int i = 0; i < chart.Series.Count; i++)
        refreshTolerances(i);
    }

    public void refreshTolerances(int numSerie)
    {
      if (chart.Series[numSerie].Visible)
      {
        Steema.TeeChart.Tools.ColorLine max = new Steema.TeeChart.Tools.ColorLine();
        max.Axis = chart.Axes.Left;
        max.Pen.Width = 2;
        max.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dot;
        max.Value = chart.Series[numSerie].MaxYValue() * 0.9;
        max.Tag = chart.Series[numSerie].Tag;
        max.Pen.Color = chart.Series[numSerie].Color;
        max.AllowDrag = false;
        chart.Tools.Add(max);

        Steema.TeeChart.Tools.ColorLine min = new Steema.TeeChart.Tools.ColorLine();
        min.Axis = chart.Axes.Left;
        min.Pen.Width = 2;
        min.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dot;
        min.Value = chart.Series[numSerie].MinYValue() * 1.1;
        min.Tag = chart.Series[numSerie].Tag;
        min.Pen.Color = chart.Series[numSerie].Color;
        min.AllowDrag = false;
        chart.Tools.Add(min);
      }
      else
      {
        // Remove lines of the serie
        for (int i = chart.Tools.Count - 1; i >= 0; i--)
        {
          if (chart.Tools[i].Tag == chart.Series[numSerie].Tag)
            chart.Tools.RemoveAt(i);
        }
      }

      chart.Refresh();
    }
  }
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

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Event to know when a serie visible property has changed

Post by acastro » Mon Jun 16, 2014 8:22 am

It is not as easy, it was only a simplification...
Is there in chartlistbox any event to detect if the visible status has changed in any serie?

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

Re: Event to know when a serie visible property has changed

Post by Narcís » Mon Jun 16, 2014 8:34 am

Hi wakeup,
wakeup wrote:It is not as easy, it was only a simplification...
That was the project you sent. Did the code I send solve the problem with that project? If it still doesn't help solve the problem with your production project, please send a Short, Self Contained, Correct (Compilable), Example project recreating the problem in your real project so that we can provide an accurate solution.
wakeup wrote:Is there in chartlistbox any event to detect if the visible status has changed in any serie?
Yes, Steema.TeeChart.ChartListBox has the ChangeActive event among many others. You can easily see all events available dropping a ChartListBox component in a form at design-time and watch the event list in the Properties windows.
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

Post Reply