Different colours for bar series

7 posts, 0 answers
  1. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 17 Aug 2015 Link to this post

    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.

  2. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 17 Aug 2015 in reply to Al Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 20 Aug 2015 Link to this post

    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
  5. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 20 Aug 2015 in reply to Danail Vasilev Link to this post

    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 

  6. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 25 Aug 2015 Link to this post

    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
  7. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 03 Sep 2015 in reply to Danail Vasilev Link to this post

    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.

     

     

  8. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 04 Sep 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017