Page 1 of 1

Event to know when a serie visible property has changed

Posted: Thu Jun 12, 2014 1:49 pm
by 15654539
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

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

Posted: Thu Jun 12, 2014 2:14 pm
by narcis
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;
        }
      }
    }

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

Posted: Fri Jun 13, 2014 8:59 am
by 15654539
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

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

Posted: Fri Jun 13, 2014 10:27 am
by narcis
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.

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

Posted: Fri Jun 13, 2014 10:53 am
by 15654539
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

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

Posted: Fri Jun 13, 2014 1:57 pm
by narcis
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();
    }
  }

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

Posted: Mon Jun 16, 2014 8:22 am
by 15654539
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?

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

Posted: Mon Jun 16, 2014 8:34 am
by narcis
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.