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

Set Bar Color

1 Answer 34 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Stephanie
Top achievements
Rank 1
Stephanie asked on 23 Dec 2013, 08:17 PM
Is there a way to set the color of the bars based on the text in a textbox?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Dec 2013, 03:32 AM
Hi Stephanie,

Please have a look into the following code snippet to change the Bar color based on the Text in the RadTextBox.

ASPX:
<telerik:RadTextBox ID="RadTextBox1" AutoPostBack="true" runat="server" EmptyMessage="Enter R or B to chnage the Bar color"
    OnTextChanged="RadTextBox1_TextChanged">
</telerik:RadTextBox>
<telerik:RadChart runat="server" ID="RadChart2">
    <Series>
        <telerik:ChartSeries Name="series 1" Type="Bar">
            <Items>
                <telerik:ChartSeriesItem YValue="50">
                </telerik:ChartSeriesItem>
                <telerik:ChartSeriesItem YValue="250">
                </telerik:ChartSeriesItem>
                <telerik:ChartSeriesItem YValue="500">
                </telerik:ChartSeriesItem>
                <telerik:ChartSeriesItem YValue="5000">
                </telerik:ChartSeriesItem>
            </Items>
        </telerik:ChartSeries>
    </Series>
</telerik:RadChart>

C#:
protected void RadTextBox1_TextChanged(object sender, EventArgs e)
{
    string Text=RadTextBox1.Text;
    foreach (ChartSeriesItem item in RadChart2.Series[0].Items)
    {
        if (Text == "R")
            item.Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
        else
            item.Appearance.FillStyle.MainColor = System.Drawing.Color.Blue;
    }
}

Thanks,
Shinu.
Tags
Chart (Obsolete)
Asked by
Stephanie
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or