|
The ranges and values of the chartcontrol are extracted from the gridgroupingcontrol's values. In the sample, the minimum and maximum values are taken from the values in the group. If the group is changed or records are changed then GroupedColumn_Changed and RecordValueChanged events are handled. An additional timer is added for the need to delay the update slightly so that the summary value is available. The drawing of the chart is done by the SetChartData method. C# private void SetChartData() { int numPoints = this.gridGroupingControl1.Table.TopLevelGroup.Groups.Count;//this.gridGroupingControl1; try { ChartSeries series = new ChartSeries(); double yMax = double.MinValue; double yMin = double.MaxValue; double xMin = double.MaxValue;//double.Parse(this.xMinTextBox.Text); 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.HidePartialLabels = 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 ChartSeries = New ChartSeries() Dim yMax As Double = Double.MinValue Dim yMin As Double = Double.MaxValue Dim xMin As Double = Double.MaxValue 'double.Parse(this.xMinTextBox.Text); Dim xMax As Double = Double.MinValue Dim j As Integer = 0 Do While j < numPoints 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) Then 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 j += 1 Loop Me.chartControl1.Indexed = False Me.chartControl1.ZoomFactorX = 1 Me.chartControl1.ZoomFactorY = 1 Me.chartControl1.PrimaryXAxis.DrawGrid = False Me.chartControl1.PrimaryYAxis.DrawGrid = False Me.chartControl1.HidePartialLabels = 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 Sample: http://websamples.syncfusion.com/samples/kb/grid.windows/GGCChart/main.htm |