1 Bar Series with different colored bar

3 posts, 0 answers
  1. Ravindra
    Ravindra avatar
    1 posts
    Member since:
    Jan 2015

    Posted 20 Feb 2015 Link to this post

    Hi Team,

    greetings from our end. the tool is performing absolutely awesome. but we got stuck up with critical requirement. before this let me tell you, we are strictly following the following url in our implementation.

    the requirement says:
    we need to set standard colors (black, white, green, red, orange, gray, .. ) for each bar we have under one and only 1 series and the color for each bar is to be defined based on dynamically mapped ProductCategoryGroup field ProductCategory from the above url.

    for eg:-
    product category is Bikes we need to have orange. 
    product category is automobiles we need to have grey.

    Now, the data source is not always loaded with same product categories list. we make load bikes, automobiles, etc:- or bikes alone or automobiles or different combination list.

  2. Nasko
    Nasko avatar
    1051 posts

    Posted 24 Feb 2015 Link to this post

    Hello Ravindra,

    The Graph item uses Color Palettes to set the series colors. For more information on the topic, please refer to the Formatting Series Colors section of the Formatting Graph Series help article.
    To change the color palette programmatically you can use the following code:
    var colors = new ColorPalette();
    colors.AddColors(Color.Blue, Color.Red, Color.Green, Color.Gray, Color.LightBlue, Color.Pink, Color.Purple);
    graph1.ColorPalette = colors;

    Note that there is no option to set a distinct color per data item in the series from a color palette. However, you can set the colors of different data points depending on their data using Conditional Formatting.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. Theo
    Theo avatar
    21 posts
    Member since:
    Sep 2011

    Posted 17 Jan Link to this post


    ProcessStatusName    TotalCount StatusOrder StatusColor
    New Process                40              1                   Black
    Awaiting Authorisation  0                2                   Chocolate
    Authorised                    19              3                    DarkGreen
    Edit After Authorisation 5               4                    MediumTurquoise
    Archived                        0               5                    Orange
    Period Review               0               6                    OrangeRed


    Report datasource is of type ObjectDataSource which is set as a datatable

    Report contains a graph that should show the different statuses as a bar graph, the bar series uses the ProcessStatusName as the datapoint and the TotalCount as the DatapointValue

    in the report code behind

    Private Sub Graph1_ItemDataBinding(sender As Object, e As EventArgs) Handles Graph1.ItemDataBinding
        Dim graphDefinition As Graph = DirectCast(sender, Processing.ReportItemBase).ItemDefinition
        Dim series As Telerik.Reporting.GraphSeriesCollection = graphDefinition.Series
        Dim reportData As DataTable = DirectCast(DirectCast(DirectCast(sender, Processing.DataItem).DataSource, ObjectDataSource).DataSource, DataTable)
        If reportData.Rows.Count > 0 Then
            For Each row As DataRow In reportData.Rows
                Dim rule As New Drawing.FormattingRule()
                rule.Filters.Add("=Fields.ProcessStatusName", FilterOperator.Equal, row("ProcessStatusName"))
                rule.Style.BackgroundColor = Color.FromName(row("StatusColor"))
                If row("StatusColor") = "Black" Then
                    rule.Style.Color = Color.White
                End If
        End If
    End Sub
Back to Top