Articles in this section

How to display the summary values of the WinForms GridGroupingControl in the essential chart?

Display summary values


The ranges and values of the Chart control are extracted from the values of the WinForms GridGroupingControl. In the sample, the minimum and maximum values are taken from the values in the group. When the groups or records change, the GroupedColumn_Changed and RecordValueChanged events are handled. An additional timer is added to delay the update slightly so that the summary value is available. The drawing of the Chart is done by the SetChartData method.

 

C#

//Hooking the GroupedColumn changes and RecordValueChanged events in the Form_Load
this.gridGroupingControl1.TableDescriptor.GroupedColumns.Changed += new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changed);
this.gridGroupingControl1.RecordValueChanged += new RecordValueChangedEventHandler(gridGroupingControl1_RecordValueChanged);

//Changes the Chart data
private void GroupedColumns_Changed(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
{
   SetChartData();
}

//Need to delay the update slightly so the summary value is available
private Timer t = null;
private void gridGroupingControl1_RecordValueChanged(object sender, RecordValueChangedEventArgs e)
{
   if(t == null)
   {
      t = new Timer();
      t.Interval = 20;
      t.Tick += new EventHandler(t_Tick);
   }
   t.Start();
}

private void t_Tick(object sender, EventArgs e)
{
   Timer t = sender as Timer;
   t.Stop();
   SetChartData();
}
VB
'Hooking the GroupedColumn changes and RecordValueChanged events in the Form_Load
AddHandler Me.gridGroupingControl1.TableDescriptor.GroupedColumns.Changed, AddressOf GroupedColumns_Changed
AddHandler Me.gridGroupingControl1.RecordValueChanged, AddressOf gridGroupingControl1_RecordValueChanged

'Changes the Chart data
Private Sub GroupedColumns_Changed(ByVal sender As Object, ByVal e As Syncfusion.Collections.ListPropertyChangedEventArgs)
    SetChartData()
End Sub

'Need to delay the update slightly so the summary value is available
Private t As Timer = Nothing
Private Sub gridGroupingControl1_RecordValueChanged(ByVal sender As Object, ByVal e As RecordValueChangedEventArgs)
    If t Is Nothing Then
        t = New Timer()
        t.Interval = 20
        AddHandler t.Tick, AddressOf t_Tick
    End If
    t.Start()
End Sub

Private Sub t_Tick(ByVal sender As Object, ByVal e As EventArgs)
    Dim t As Timer = TryCast(sender, Timer)
    t.Stop()
    SetChartData()
End Sub
SetChartData method


In this method, the properties of the Chart are set. Based on the Summary values of the GridGroupingControl, the Chart is drawn.

 

C#

private void SetChartData()
{
    int numPoints = this.gridGroupingControl1.Table.TopLevelGroup.Groups.Count;
    try
    {
        ChartSeries series = new ChartSeries();
        double yMax = double.MinValue;
        double yMin = double.MaxValue;
        double xMin = double.MaxValue;
        double xMax = double.MinValue;
        for (int j = 0; j < numPoints; j++)
        {
            Group g = this.gridGroupingControl1.Table.TopLevelGroup.Groups[j];
            double x;
            double y;
            if (double.TryParse(g.Category.ToString(), System.Globalization.NumberStyles.Any, null, out x) && double.TryParse(GridEngine.GetSummaryText(g, this.scd), System.Globalization.NumberStyles.Any, null, out y))
            {
                series.Points.Add(x, y);
                if (y < yMin)
                    yMin = y;
                if (y > yMax)
                    yMax = y;
                if (x < xMin)
                    xMin = x;
                if (x > xMax)
                    xMax = x;
            }
        }
        this.chartControl1.Indexed = false;
        this.chartControl1.ZoomFactorX = 1;
        this.chartControl1.ZoomFactorY = 1;
        this.chartControl1.PrimaryXAxis.DrawGrid = false;
        this.chartControl1.PrimaryYAxis.DrawGrid = false;
        this.chartControl1.PrimaryYAxis.RangeType = ChartAxisRangeType.Set;
        this.chartControl1.PrimaryYAxis.Range.Max = yMax;
        this.chartControl1.PrimaryYAxis.Range.Min = yMin;
        this.chartControl1.PrimaryYAxis.Range.Interval = (yMax - yMin) / 4;
        this.chartControl1.PrimaryYAxis.Font = new Font(this.Font.Name, 8);
        this.chartControl1.PrimaryXAxis.RangeType = ChartAxisRangeType.Set;
        this.chartControl1.PrimaryXAxis.Range.Max = xMax;
        this.chartControl1.PrimaryXAxis.Range.Min = xMin;
        this.chartControl1.PrimaryXAxis.Range.Interval = 2;
        this.chartControl1.Legend.Visible = false;
        series.Type = ChartSeriesType.Line;
        series.Style.DisplayShadow = false;
        this.chartControl1.Series.Add(series);
        this.chartControl1.Redraw(true);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
VB
Private Sub SetChartData()
    Dim numPoints As Integer = Me.gridGroupingControl1.Table.TopLevelGroup.Groups.Count
    Try
        Dim series As New ChartSeries()
        Dim yMax As Double = Double.MinValue
        Dim yMin As Double = Double.MaxValue
        Dim xMin As Double = Double.MaxValue
        Dim xMax As Double = Double.MinValue
        For j As Integer = 0 To numPoints - 1
            Dim g As Group = Me.gridGroupingControl1.Table.TopLevelGroup.Groups(j)
            Dim x As Double
            Dim y As Double
            If Double.TryParse(g.Category.ToString(), System.Globalization.NumberStyles.Any, Nothing, x) AndAlso Double.TryParse(GridEngine.GetSummaryText(g, Me.scd), System.Globalization.NumberStyles.Any, Nothing, y) 
                series.Points.Add(x, y)
                If y < yMin Then
                    yMin = y
                End If
                If y > yMax Then
                    yMax = y
                End If
                If x < xMin Then
                    xMin = x
                End If
                If x > xMax Then
                    xMax = x
                End If
            End If
        Next j
        Me.chartControl1.Indexed = False
        Me.chartControl1.ZoomFactorX = 1
        Me.chartControl1.ZoomFactorY = 1
        Me.chartControl1.PrimaryXAxis.DrawGrid = False
        Me.chartControl1.PrimaryYAxis.DrawGrid = False
        Me.chartControl1.PrimaryYAxis.RangeType = ChartAxisRangeType.Set
        Me.chartControl1.PrimaryYAxis.Range.Max = yMax
        Me.chartControl1.PrimaryYAxis.Range.Min = yMin
        Me.chartControl1.PrimaryYAxis.Range.Interval = (yMax - yMin) / 4
        Me.chartControl1.PrimaryYAxis.Font = New Font(Me.Font.Name, 8)
        Me.chartControl1.PrimaryXAxis.RangeType = ChartAxisRangeType.Set
        Me.chartControl1.PrimaryXAxis.Range.Max = xMax
        Me.chartControl1.PrimaryXAxis.Range.Min = xMin
        Me.chartControl1.PrimaryXAxis.Range.Interval = 2
        Me.chartControl1.Legend.Visible = False
        series.Type = ChartSeriesType.Line
        series.Style.DisplayShadow = False
        Me.chartControl1.Series.Add(series)
        Me.chartControl1.Redraw(True)
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub
The following screenshot displays the summary value in the Chart.

Show summary values in chart


Samples
:

C#: GGCChart-C#1445073499.zip

VB: GGCChart-VB1929825338.zip


Conclusion


I hope you enjoyed learning about how to display the summary values of the GridGroupingControl in the essential chart.


You can refer to our WinForms GridGroupingControl  feature tour page to know about its other groundbreaking feature representations and WinForms GridGroupingControl documentation, and how to quickly get started for configuration specifications.

 

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

 

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied