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

Different colours for bar series

6 Answers 254 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Iron
Iron
Iron
Al asked on 17 Aug 2015, 08:56 AM

Hi,

My bar chart uses only one colour for all series, how can I get it to use random colours? (or generate a custom palette myself).

Preferably to be set in code-behind.

6 Answers, 1 is accepted

Sort by
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 17 Aug 2015, 02:40 PM
I may have used the wrong terminology - my chart only has one series of values and I want to change the colour of each bar in that series
0
Danail Vasilev
Telerik team
answered on 20 Aug 2015, 05:18 AM
Hello Al,

For a data-bound chart you can use the ColorField property (http://demos.telerik.com/aspnet-ajax/htmlchart/examples/functionality/custombarcolor/defaultcs.aspx), while for a programmatically created chart you can use the BackgroundColor property of the item:

(LineChart.PlotArea.Series[0] as LineSeries).SeriesItems[0].BackgroundColor = System.Drawing.Color.Red;


Regards,
Danail Vasilev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 20 Aug 2015, 08:39 AM

Hi Danial,

Thanks, where do I use the programmatic approach, when I used it in the routine that builds my charts I got this error:

  (chtUsers.PlotArea.Series[0] as LineSeries) -    The type or namespace name 'LineSeries' is not valid in this scope 

0
Danail Vasilev
Telerik team
answered on 25 Aug 2015, 05:24 AM
Hi Al,

You should use the Telerik namespace:

using Telerik.Web.UI;

You can also add it to Visual Studio with a short cut - click on the unknown word (LineSeries) and press CTRL + "."

Regards,
Danail Vasilev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Sep 2015, 11:41 AM

The problem wasn't the Telerik.web.ui reference, I think it was because mine is a ColumnChart so I used this code:

(chtUsers.PlotArea.Series[0] as ColumnSeries).SeriesItems[0].BackgroundColor = System.Drawing.Color.Red;

The problem is that although my ColumnSeries is valid, it's SeriesItems is empty - I have just posted a support ticket for the same problem.

 

 

0
Marin Bratanov
Telerik team
answered on 04 Sep 2015, 07:17 AM

Hello Al,

I have answered your ticket and I am pasting my response here for anyone else that may have a similar question and stumble on this thread:

RadHtmlChart works entirely on the client, so it also binds on the client to its data, so the server items collection is empty, and this is the expected behavior of the control: http://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/troubleshooting/known-issues/known-limitations.

As for the BackgroundColor property - its default value is  System.Drawing.Color.Empty so if you have not set it previously in the code, an empty value is to be expected. The skins (that are also based on JavaScript for this control) may change the default value of this property when rendering the chart, if the developer has not set a value explicitly, but this is not shown on the server side.

Regards,

Marin Bratanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart (HTML5)
Asked by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Danail Vasilev
Telerik team
Marin Bratanov
Telerik team
Share this question
or