Set Series Gradient Color with VB

Thread is closed for posting
4 posts, 0 answers
  1. Tim Sledge
    Tim Sledge avatar
    2 posts
    Member since:
    May 2008

    Posted 16 Nov 2008 Link to this post

    I'm attempting to set a bar in a chart to gradient color using the following code, but something is missing.  What else do I need?

    chartSeries.Type = ChartSeriesType.Bar

    chartSeries.Appearance.FillStyle.MainColor = Drawing.Color.Beige

    chartSeries.Appearance.FillStyle.SecondColor = Drawing.Color.Aqua

    chartSeries.Appearance.FillStyle.FillType = Styles.FillType.ComplexGradient

    I get the following error message...

    ColorBlend object that was set is not valid.Array of colors and positions must contain at least two elements. ColorBlend objects must be constructed with the same number of positions and color values. Positions must be between 0.0 and 1.0, 1.0 indicating the last element in the array.

  2. Giuseppe
    Giuseppe avatar
    2363 posts

    Posted 17 Nov 2008 Link to this post

    Hi Tim Sledge,

    If you would like to use complex gradient, you need to supply the desired colors via the ChartSeries.Appearance.FillStyle.FillSettings.ComplexGradient collection property like this:

    Dim series As ChartSeries = New ChartSeries 
    series.Type = ChartSeriesType.Bar 
    series.Appearance.FillStyle.FillSettings.ComplexGradient.Add(New GradientElement(Drawing.Color.Red, 0)) 
    series.Appearance.FillStyle.FillSettings.ComplexGradient.Add(New GradientElement(Drawing.Color.Green, 0.5)) 
    series.Appearance.FillStyle.FillSettings.ComplexGradient.Add(New GradientElement(Drawing.Color.Blue, 1)) 
    series.Appearance.FillStyle.FillType = Styles.FillType.ComplexGradient 

    Alternatively, if you would like to use simple gradient you can do it like this:

    Dim series As ChartSeries = New ChartSeries 
    series.Type = ChartSeriesType.Bar 
    series.Appearance.FillStyle.MainColor = Drawing.Color.Beige 
    series.Appearance.FillStyle.SecondColor = Drawing.Color.Aqua 
    series.Appearance.FillStyle.FillType = Styles.FillType.Gradient 

    Best wishes,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. D
    D avatar
    3 posts
    Member since:
    Mar 2011

    Posted 15 Apr 2011 Link to this post

    what would the C# equivalent of this be?  I've tried a thousand different ways...  thx!
  4. Missing user
    Missing user avatar

    Posted 20 Apr 2011 Link to this post


    You can use our Code Converter to translate these code snippets to C#.

    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top