ComponentOne Chart for .NET (2.0) Search HelpCentral 

Creating a Gradient Brush

The following sample code represents the handler that creates linear gradient brush.

Please note that the given code snippet shows the initial declarations of some objects using their full namespace. In subsequent use of those and related objects, the namespace is omitted for brevity.

·      Visual Basic

Private Sub C1Chart1_DrawDataSeries(ByVal sender As Object, _
    ByVal e As C1.Win.C1Chart.DrawDataSeriesEventArgs) _
   Handles C1Chart1.DrawDataSeries

 

  Dim ds As C1.Win.C1Chart.ChartDataSeries = sender

  Dim clr1 As Color = ds.LineStyle.Color

  Dim clr2 As Color = ds.SymbolStyle.Color

 

  If(e.Bounds.Height > 0 And e.Bounds.Width > 0) Then
    Dim lgb As System.Drawing.Drawing2D.LinearGradientBrush = _
      New LinearGradientBrush(e.Bounds, clr1, clr2, LinearGradientMode.Horizontal)
    e.Brush = lgb

  End If

End Sub

·      C#

private void c1Chart1_DrawDataSeries(object sender,

   C1.Win.C1Chart.DrawDataSeriesEventArgs e)

{

  C1.Win.C1Chart.ChartDataSeries ds = (ChartDataSeries)sender;

  Color clr1 = ds.LineStyle.Color;

  Color clr2 = ds.SymbolStyle.Color;

  if(e.Bounds.Size.Height > 0 && e.Bounds.Size.Width > 0)

  {

    System.Drawing.Drawing2D.LinearGradientBrush lgb =
      new LinearGradientBrush(e.Bounds, clr1, clr2, LinearGradientMode.Horizontal);

    e.Brush = lgb;

  }

}

·      Delphi

procedure Class1.c1Chart1_DrawDataSeries(sender: System.Object;
  e: C1.Win.C1Chart.DrawDataSeriesEventArgs);

var

  ds: C1.Win.C1Chart.ChartDataSeries;

  forecolor:  Color;

  backcolor:  Color;

  lgb: System.Drawing.Drawing2D.LinearGradientBrush;

begin

  ds := ChartDataSeries(sender);

  forecolor := ds.SymbolStyles.Color;

  backcolor := ds.LineStyle.Color;

  lgb := LinearGradientBrush.Create(HatchStyle.OutlinedDiamond,

             forecolor, backcolor;

  e.Brush := lgb;

end;

The following image shows the linear gradient brush:


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.