Set Bar Color

Thread is closed for posting
2 posts, 0 answers
  1. Stephanie
    Stephanie avatar
    8 posts
    Member since:
    Dec 2013

    Posted 23 Dec 2013 Link to this post

    Is there a way to set the color of the bars based on the text in a textbox?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Dec 2013 Link to this post

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