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

Get Dynamic Skin Colors

4 Answers 134 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 05 Oct 2012, 08:51 PM
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.

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 08 Oct 2012, 10:52 AM
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.
0
Rob
Top achievements
Rank 1
answered on 08 Oct 2012, 12:30 PM
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.

0
Marin Bratanov
Telerik team
answered on 09 Oct 2012, 12:30 PM
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.
0
Rob
Top achievements
Rank 1
answered on 09 Oct 2012, 12:31 PM
Thanks for this Marin.  I will check it out.
Tags
Chart (HTML5)
Asked by
Rob
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Rob
Top achievements
Rank 1
Share this question
or