We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Chart multiple points selections

Thread ID:

Created:

Updated:

Platform:

Replies:

115998 Mar 13,2014 02:09 PM UTC Mar 18,2014 03:12 PM UTC WinForms 3
loading
Tags: Chart
ageb
Asked On March 13, 2014 02:09 PM UTC

Hi,
May I know if the windows chart able to do multiple selection of points in a chart (like zoom selection)?
And also highlighted the data in a gridcontrol?
I need this kind of control for my next project and currently, i'm evaluating syncfusion which i see is very helpful to me.
Im using VS2010 VB.net.

Thank you.
-Ageb


Anandaraj T [Syncfusion]
Replied On March 14, 2014 07:36 AM UTC

Hi Ageb,

Thanks for using Syncfusion products.

Query #1: May I know if the windows chart able to do multiple selection of points in a chart (like zoom selection)?

We can achieve this using mouse down, mouse up and mouse move events of Chart.

Please refer the following code snippet to achieve this.
<code>
[CS]
            //Mouse Down, Up and Move events for Chart to select points in Chart
            this.chartControl1.ChartRegionMouseDown += chartControl1_ChartRegionMouseDown;
            this.chartControl1.ChartRegionMouseUp += chartControl1_ChartRegionMouseUp;
            this.chartControl1.ChartRegionMouseMove += chartControl1_ChartRegionMouseMove;

        //Mouse down event for Chart
        void chartControl1_ChartRegionMouseDown(object sender, ChartRegionMouseEventArgs e)
        {
            if (!MouseSelection)
            {
                this.chartControl1.Refresh();
                ChartMouseDown = e.Point;
                MouseSelection = true;
            }       
        }

        //Mouse move event for Chart
        void chartControl1_ChartRegionMouseMove(object sender, ChartRegionMouseEventArgs e)
        {
            if (MouseSelection)
                DrawSelectionArea(ChartMouseDown, e.Point);
        }

        //Mouse Up event for Chart
        void chartControl1_ChartRegionMouseUp(object sender, ChartRegionMouseEventArgs e)
        {
            if (MouseSelection)
            {
                ChartMouseUp = e.Point;
                this.chartControl1.Refresh();
                HighLightGrid(ChartMouseDown, ChartMouseUp);
                MouseSelection = false;
            }
        }

        //Drawing a rectangle in the selected area of Chart(Similar to Zooming)
        void DrawSelectionArea(PointF down, PointF up)
        {
            if (down.X > up.X)
            {
                float x = up.X;
                up.X = down.X;
                down.X = x;
            }

            if (down.Y > up.Y)
            {
                float y = up.Y;
                up.Y = down.Y;
                down.Y = y;
            }
          
            this.chartControl1.Refresh();
            Brush selectionColor = new SolidBrush(Color.FromArgb(50, Color.Blue));
            Graphics g = this.chartControl1.GetGraphics();
            g.FillRectangle(selectionColor, down.X, down.Y, Math.Abs(down.X-up.X), Math.Abs(down.Y-up.Y));
        }

</code>

Query #2: And also highlighted the data in a gridcontrol?

We can highlight data in grid using "Selections" property of grid.

Please refer the following code snippet to achieve this.
<code>
[CS]
         //Highlighting records in Grid
        void HighLightGrid(PointF down, PointF up)
        {
            ChartPoint DownPoint = this.chartControl1.ChartArea.GetValueByPoint(new Point((int)down.X, (int)down.Y));
            ChartPoint UpPoint = this.chartControl1.ChartArea.GetValueByPoint(new Point((int)up.X, (int)up.Y));          
            List<double> data = new List<double>();

            foreach (ChartSeries series in this.chartControl1.Series)
                foreach (ChartPoint point in series.Points)
                    if ((DownPoint.X <= point.X && UpPoint.X >= point.X && DownPoint.YValues[0] >= point.YValues[0] && UpPoint.YValues[0] <= point.YValues[0]) || (DownPoint.X >= point.X && UpPoint.X <= point.X && DownPoint.YValues[0] <= point.YValues[0] && UpPoint.YValues[0] >= point.YValues[0]) || (DownPoint.X <= point.X && UpPoint.X >= point.X && DownPoint.YValues[0] <= point.YValues[0] && UpPoint.YValues[0] >= point.YValues[0]) || (DownPoint.X >= point.X && UpPoint.X <= point.X && DownPoint.YValues[0] >= point.YValues[0] && UpPoint.YValues[0] <= point.YValues[0]))
                        //Adding the points selected in Chart to a list
                        data.Add(point.X);
                     
            //Selecting Grid Data
            this.gridDataBoundGrid1.Selections.Clear();           
            for (int i = 1; i < this.gridDataBoundGrid1.Model.RowCount; i++)
            {
                double cellValue = Convert.ToDouble(this.gridDataBoundGrid1[i, 1].CellValue);
                if(data.Contains(cellValue))
                    this.gridDataBoundGrid1.Selections.Add(GridRangeInfo.Row(i));
            }
        }
</code>

For your convenience, we have created a simple sample based on your requirements and it can be downloaded from the following link.
www.syncfusion.com/downloads/support/directtrac/general/PointsSelection7839488.zip

Please let us know if you have any concern.

Regards,
Anand

ageb
Replied On March 16, 2014 11:07 AM UTC

Hi Anand,
Thank you for your quick response.
The sample code you provide is fit for our requirements.  I did some testing and it works.

I have another question and need to verify if this function is supported.
CHART
1. How about the individual points selection using the CTRL + leftclick?  
    i.e. 5 points, user only select the 1 & 5 points using the CTRL+leftclick.
2. NO 3D Surface Chart in Windows functions? 

GRID CONTROL/GRID DATA BOUND
3. Filter-TO function - it display rows selected by the user and hide the unselected rows.
    Filter-OUT function - it will hide the rows selected by the user and display ALL not selected.


Note: If you can provide a sample, can you do it in VS2010.

Thank you.

Regards,
Ageb

Anandaraj T [Syncfusion]
Replied On March 18, 2014 03:12 PM UTC

Hi Ageb,

Thanks for the update.

Query :
How about the individual points selection using the CTRL + leftclick? Filter-TO and Filter-OUT functions for grid control.

We have modified the sample in our previous update for highlighting first and last points of chart when using “Ctrl + leftclick” and methods to display selected and unselected rows in grid. The modified sample can be downloaded from the following link.

PointsSelection_Modified.zip

Please refer the following code snippet to achieve this.

<code>

[VB]

              'Click event for Chart Control

              AddHandler Me.chartControl1.ChartRegionClick, AddressOf chartControl1_ChartRegionClick

              'Key events for Form

              Me.KeyPreview = True

              AddHandler Me.KeyDown, AddressOf Form1_KeyDown

              AddHandler Me.KeyUp, AddressOf Form1_KeyUp

              'Key up event

              Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs)

                     CtrlKeyDown = False

              End Sub

              'Click event for Chart Control

              Private Sub chartControl1_ChartRegionClick(ByVal sender As Object, ByVal e As ChartRegionMouseEventArgs)

                     If CtrlKeyDown Then

                           HighLightGrid()

                     End If

              End Sub

             

'Method to highlight first and last point of Grid

              Private Sub HighLightGrid()

                     Dim data As New List(Of Double)()

                     For Each series As ChartSeries In Me.chartControl1.Series

                           data.Add(series.Points(0).X)

                           data.Add(series.Points(series.Points.Count - 1).X)

                     Next series

                     'Selecting Grid Data

                     Me.gridDataBoundGrid1.Selections.Clear()

                     For i As Integer = 1 To Me.gridDataBoundGrid1.Model.RowCount - 1

                           Dim cellValue As Double = Convert.ToDouble(Me.gridDataBoundGrid1(i, 1).CellValue)

                           If data.Contains(cellValue) Then

                                  Me.gridDataBoundGrid1.Selections.Add(GridRangeInfo.Row(i))

                           End If

                     Next i

              End Sub

              'Key down event to select first and last points when "Ctrl" and left click is performed

              Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)

                     If e.KeyCode.ToString().Equals("ControlKey") Then

                           CtrlKeyDown = True

                     Else

                           CtrlKeyDown = False

                     End If

              End Sub

              'Hiding unselected rows in grid

              Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click

                     FilterTO(True)

              End Sub

              'Hiding selected rows in grid

              Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click

                     FilterTO(False)

              End Sub

              'Method for FilterTO or FilterOUT

              Private Sub FilterTO(ByVal IsFilterTO As Boolean)

                     For i As Integer = 1 To Me.gridDataBoundGrid1.Model.RowCount - 1

                           Me.gridDataBoundGrid1.Model.Rows.Hidden(i) = IsFilterTO

                     Next i

                     Dim selectedList As GridRangeInfoList = Me.gridDataBoundGrid1.Selections.Ranges.GetRowRanges(GridRangeInfoType.Rows)

                     Dim selectedRow As New List(Of Integer)()

                     Dim rowCollection() As String = selectedList.Info.Split(New Char() { ";"c })

                     For Each row As String In rowCollection

                           If Not String.IsNullOrWhiteSpace(row) Then

                                  row.Replace(" ", String.Empty)

                                  Dim rowRanges() As String = row.Split(":"c)

                                  If rowRanges.Length = 1 Then

                                         rowRanges(0)=rowRanges(0).Replace(" ", String.Empty)

                                         If Not String.IsNullOrWhiteSpace(rowRanges(0)) Then

                                         selectedRow.Add(Convert.ToInt32(rowRanges(0).Remove(0, 1)))

                                         End If

                                  Else

                                         rowRanges(0)=rowRanges(0).Replace(" ", String.Empty)

                                         rowRanges(1)=rowRanges(1).Replace(" ", String.Empty)

                                         Dim startRange As Integer = Convert.ToInt32(rowRanges(0).Remove(0, 1))

                                         Dim endRange As Integer = Convert.ToInt32(rowRanges(1).Remove(0, 1))

                                         For k As Integer = startRange To endRange

                                                selectedRow.Add(k)

                                         Next k

                                  End If

                           End If

                     Next row

                     For Each index As Integer In selectedRow

                     Me.gridDataBoundGrid1.Model.Rows.Hidden(index) = Not IsFilterTO

                     Next index

              End Sub

</code>

Query : 3D surface charts in windows functions?

Currently, support for surface chart is not available in Essential Windows forms Chart. We have already logged a feature request in our features management system.

http://www.syncfusion.com/support/directtrac/features/WF-4457

Please let us know if you have any concern.

Regards,

Anand



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;