Get Dynamic Skin Colors

5 posts, 0 answers
  1. Rob
    Rob avatar
    27 posts
    Member since:
    Oct 2012

    Posted 05 Oct 2012 Link to this post

    I'm utilizing the RadHTMLChart for a pie chart.  I specify some of the series colors but not all.  I have colors assigned to a variable that is referenced by the PieSeries ColorField.  The ones I want to be pulled dynamically from the Skin I leave as "", empty string.

    What I Have

            protected IList<DataChart> GetChartData()
            {
                IList<DataChart> dataCharts = new List<DataChart>();
                int totalNumber = 0;
                foreach (Summary summary in DataSource)
                {
                    totalNumber += summary.Count;
                }
     
                foreach (Summary summary in DataSource)
                {
                    DataChart thisChart = new DataChart(summary);
                    thisChart.ChartCount = Math.Round(100 / ((float)totalNumber / summary.Count),2);
                    thisChart.ChartLabel = summary.Code;
                    thisChart.ChartColor = GetColorByCode(summary.Code);
                    thisChart.ChartExplode = someCondition ? "true" : "";
                    dataCharts.Add(thisChart);
                }
                return dataCharts;
    }
     
            protected string GetColorByCode(string code)
            {
                string color;
                switch (code)
                {
                    case "BP":
                        color = "#d35151";
                        break;
                    case "RS":
                        color = "#f0e45e";
                        break; 
                    case "XT":
                        color = "#ff6600";
                        break; 
                    default:
                        color = "";
                        break;
                }
                return color;
            }


    Is there a way that in the code-behind, I could programmatically use the WebResource (or something else) to get the color(s) from the skin?  I need the color for something else besides the chart.  Thus I'd never leave the value for the ColorField as "" but some I'd assign specifically and some I'd assign by dynamically getting a color from the skin.  It would be done in the "default" of the switch.

    If there's another way to do this, I'm all ears.

    Thanks.
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 08 Oct 2012 Link to this post

    Hello Robert,

    I am afraid there isn't a way to get the predefined colors during runtime in the code-behind. Because of the control's client-side rendering the skins are also set through a JavaScript object that holds default properties. If you want I can give you a list with the default colors we use so you can incorporate it in your logic (e.g. as a static dictionary - the key could be the skin name, a string array can be used to get the desired index color).


    Greetings,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob
    Rob avatar
    27 posts
    Member since:
    Oct 2012

    Posted 08 Oct 2012 Link to this post

    I'd very much appreciate a list of the default web colors.  If I can get the color client side readily, I appreciate that information as well.  I hadn't yet investigated a way but maybe I can get the fill colors with jquery.  If you've already got something designed I could use, that's great.

    I would appreciate the color information for:  WebBlue & Office2010Blue.  Thank you very much.

  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 09 Oct 2012 Link to this post

    Hello Robert,

    You can find the colors with the following function:
    function getColors()
    {
        var chart = $find("RadHtmlChart1");
        var colorsArray = chart._chartObject.options.seriesColors;
        for (var i = 0; i < colorsArray.length; i++)
        {
            console.log(colorsArray[i]);
        }
    }

    This is not designed for external use, just an object that holds the values. I cannot guarantee it will always work.

    On the colors we now use - I am pasting below the list for the skins you asked for:
    WebBlue: "#a2b3c7", "#76c8e8", "#358db0", "#426682", "#2d3d4f"
    Office2010Blue: "#99c62a", "#27adcc", "#2477c9", "#7042b2", "#d83636"

    I hope you find it useful. Note that we may add more in the future, but this will not happen with the initial Q3 2012 release.

    Regards,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Rob
    Rob avatar
    27 posts
    Member since:
    Oct 2012

    Posted 09 Oct 2012 Link to this post

    Thanks for this Marin.  I will check it out.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017