Hover support in .net version.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
netdeveloper
Newbie
Newbie
Posts: 5
Joined: Fri Jun 10, 2016 12:00 am

Hover support in .net version.

Post by netdeveloper » Tue Jun 14, 2016 5:44 pm

Hi I am migrating an old software written in Delphi to .net Winform application. Every things works perfectly well except I could not find a chart hover functionality in .net version. Please see attached image
Hover option in Delphi version
1.PNG
1.PNG (18.92 KiB) Viewed 9443 times

In Delphi version when I hover the mouse over the series, it highlights the line with red color and this was built in functionality in Delphi chart. see attached image
Following is the effect.
1b.png
1b.png (5.14 KiB) Viewed 9434 times


I would like to achieve the same in .net version, please advice how to do this.

Thankyou

netdeveloper
Newbie
Newbie
Posts: 5
Joined: Fri Jun 10, 2016 12:00 am

Re: Hover support in .net version.

Post by netdeveloper » Tue Jun 14, 2016 5:50 pm

i am using TeeChartNET2016_4.1.2016.05120.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Hover support in .net version.

Post by Christopher » Wed Jun 15, 2016 1:27 pm

netdeveloper wrote:i am using TeeChartNET2016_4.1.2016.05120.
This functionality is not presently available in TeeChart.NET, but some of it can be replicated using the current public API with code similar to the following:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Line line = new Line(tChart1.Chart);

      line.FillSampleValues();
      tChart1.Legend.ResizeChart = false;
      tChart1.Legend.Left = tChart1.Width - 70;
      tChart1.Legend.Top = 100;
      tChart1.Legend.CustomPosition = true;
      tChart1.Panel.MarginRight = 10;

      tChart1.MouseMove += TChart1_MouseMove;

    }

    private int seriesIndex = -1;
    private int legendIndex = -1;
    private string legendItem = null;

    private void TChart1_MouseMove(object sender, MouseEventArgs e)
    {
      ChartClickedPart chartPart = tChart1.Chart.CalcClickedPart(e.Location);

      Action<Series, int> DoIndSeries = (ASeries, AIndex) =>
      {
        if (seriesIndex > -1)
          ASeries[seriesIndex + 1].Color = ASeries.Color;

        seriesIndex = AIndex;
        ASeries[seriesIndex + 1].Color = Color.Red;
      };

      Action<Series> DoSeries = (ASeries) =>
      {
        if (seriesIndex > -1)
          ASeries[seriesIndex + 1].Color = ASeries.Color;

        seriesIndex = ASeries.Clicked(e.Location);
        ASeries[seriesIndex + 1].Color = Color.Red;
      };

      Action DoLegend = () =>
      {
        LegendItem item;

        if(legendItem != null)
        {
          item = tChart1.Legend.Items[legendIndex];
          item.Text = legendItem;
        }

        legendIndex = tChart1.Legend.Clicked(e.X, e.Y);
        legendItem = tChart1.Legend.Items[legendIndex].Text;
        tChart1.Legend.Items[legendIndex].Text = "*" + legendItem + "*";
      };

      Action<int> DoIndLegend = (AIndex) =>
      {
        LegendItem item;

        if (legendItem != null)
        {
          item = tChart1.Legend.Items[legendIndex];
          item.Text = legendItem;
        }

        legendIndex = AIndex;
        legendItem = tChart1.Legend.Items[legendIndex].Text;
        tChart1.Legend.Items[legendIndex].Text = "*" + legendItem + "*";
      };

      Action<Series> Reset = (ASeries) =>
      {
        if (seriesIndex > -1)
          ASeries[seriesIndex + 1].Color = ASeries.Color;

        if (legendItem != null)
        {
          LegendItem item = tChart1.Legend.Items[legendIndex];
          item.Text = legendItem;
        }
      };


      switch (chartPart.Part)
      {
        //case ChartClickedPartStyle.None:
        //  break;
        case ChartClickedPartStyle.Legend:
          DoLegend();
          DoIndSeries(tChart1[0], legendIndex);
          break;
        //case ChartClickedPartStyle.Axis:
        //  break;
        case ChartClickedPartStyle.Series:
          DoSeries(chartPart.ASeries);
          DoIndLegend(seriesIndex);
          break;
        //case ChartClickedPartStyle.Header:
        //  break;
        //case ChartClickedPartStyle.Foot:
        //  break;
        //case ChartClickedPartStyle.ChartRect:
        //  break;
        //case ChartClickedPartStyle.SeriesMarks:
        //  break;
        //case ChartClickedPartStyle.SeriesPointer:
        //  break;
        //case ChartClickedPartStyle.SubHeader:
        //  break;
        //case ChartClickedPartStyle.SubFoot:
        //  break;
        //case ChartClickedPartStyle.AxisTitle:
        //  break;
        default:
          Reset(tChart1[0]);
          break;
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

netdeveloper
Newbie
Newbie
Posts: 5
Joined: Fri Jun 10, 2016 12:00 am

Re: Hover support in .net version.

Post by netdeveloper » Wed Jun 15, 2016 9:37 pm

Thankyou Christopher.
this is exactly what i was looking to implement. but one problem when mouse leaves the series it should re apply series color on the line instead of red. Currently when mouse leaves the series it left the line red. please see attached image
Untitled-1.png
Untitled-1.png (8.85 KiB) Viewed 9394 times

can you tell me how to reset the color when mouse leaves the series...?? so as per example if mouse leaves the series it should be green..

netdeveloper
Newbie
Newbie
Posts: 5
Joined: Fri Jun 10, 2016 12:00 am

Re: Hover support in .net version.

Post by netdeveloper » Wed Jun 15, 2016 11:41 pm

hi also i am using following code to create 12 series in chart

Code: Select all

 tChart1.Aspect.View3D = false;
                tChart1.Panel.Bevel.Inner = BevelStyles.None;
                tChart1.Panel.Bevel.Outer = BevelStyles.None;


                Graphics3DDirect2D D2D = new Graphics3DDirect2D(tChart1.Chart);
                D2D.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                D2D.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                tChart1.Graphics3D = D2D;
                tChart1.Graphics3D.BufferStyle = BufferStyle.None;

                tChart1.Axes.Bottom.Grid.Visible = false;


for( w = 0; w<12;w++)
            {
                
                series = tChart.Series.Add(new Steema.TeeChart.Styles.FastLine() { LinePen = p, Color=Color.Black });
               series.Color= Color.Black;
                series.Tag = w;

                       }
/// some where in code adding points like this
///
chartControl.Chart.Series[w].Add(x, y);


//now it is not working with that series...

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Hover support in .net version.

Post by Christopher » Thu Jun 16, 2016 7:49 am

netdeveloper wrote:can you tell me how to reset the color when mouse leaves the series...?? so as per example if mouse leaves the series it should be green..
The code I posted does this, but only does so if there is one series in the chart. You will need to modify the code so it keeps a record of the last series, in a similar way my code snippet keeps a record of the last seriesIndex.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply