This is a migrated thread and some comments may be shown as answers.

1 Bar Series with different colored bar

2 Answers 252 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ravindra
Top achievements
Rank 1
Ravindra asked on 20 Feb 2015, 10:46 AM
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.
http://www.telerik.com/help/reporting/graphhowtocreateprogrammaticallygraph.html


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 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 24 Feb 2015, 04:30 PM
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.

Regards,
Nasko
Telerik
 

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.

 
0
Theo
Top achievements
Rank 2
answered on 18 Jan 2019, 05:26 AM

Data

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
    series(0).DataPointConditionalFormatting.Clear()
    series(0).DataPointLabelConditionalFormatting.Clear()
 
    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
                series(0).DataPointLabelConditionalFormatting.Add(rule)
            End If
            series(0).DataPointConditionalFormatting.Add(rule)
        Next
    End If
End Sub
Tags
General Discussions
Asked by
Ravindra
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Theo
Top achievements
Rank 2
Share this question
or