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

Change color based on a condition

3 Answers 112 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jon Morris
Top achievements
Rank 1
Jon Morris asked on 05 Oct 2010, 04:07 PM
Hi,

Is there a way to change the color of a series based on a condition? For eg: I am plotting a line chart with a series with values between 0 and 200.Is there a way to change the color of the series if it goes past 100?

Thanks,
Sri

3 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 07 Oct 2010, 03:29 PM
Hello Jon,

Indeed you can change Line series color. For example if you have series items with these values:
 
<telerik:radchart ID="RadChart1" runat="server" DefaultType="Line">
         <Series>
             <telerik:ChartSeries Name="Series 1" Type="Line">
                 <Appearance>
                     <FillStyle MainColor="213, 247, 255">
                     </FillStyle>
                 </Appearance>
                 <Items>
                     <telerik:ChartSeriesItem Name="Item 1" YValue="45">
                     </telerik:ChartSeriesItem>
                     <telerik:ChartSeriesItem Name="Item 2" YValue="78">
                     </telerik:ChartSeriesItem>
                     <telerik:ChartSeriesItem Name="Item 3" YValue="29">
                     </telerik:ChartSeriesItem>
                     <telerik:ChartSeriesItem Name="Item 4" YValue="99">
                     </telerik:ChartSeriesItem>
                     <telerik:ChartSeriesItem Name="Item 5" YValue="200">
                     </telerik:ChartSeriesItem>
                 </Items>
             </telerik:ChartSeries>
         </Series>
        </telerik:radchart>

You can use FillType.MainColor property of the series to set custom color for them. Setting color based on condition is as simple as this:

foreach (ChartSeriesItem item in RadChart1.Series[0].Items)
            {
                if (item.YValue > 100)
                {
                    RadChart1.Series[0].Appearance.FillStyle.MainColor = Color.Purple;
                }
            }

In this case Line will be shown with purple color as one of its items has Yvalue 200.

I hope this helps.

Greetings,
Evgenia
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Muthu
Top achievements
Rank 1
answered on 23 Apr 2013, 10:24 AM
How to do the same on javascript html controls?
0
Petar Kirov
Telerik team
answered on 25 Apr 2013, 02:19 PM
Hi Muthu,

With the ASP.NET AJAX HtmlChart you can use the Appearance.FillStyle.BackgroundColor property of the LineSeries. In this help topic you read more about that.
 
I hope this helps.

All the best,
Petar Kirov
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.
Tags
Chart (Obsolete)
Asked by
Jon Morris
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Muthu
Top achievements
Rank 1
Petar Kirov
Telerik team
Share this question
or