Change color of bar in bar chart

Thread is closed for posting
2 posts, 0 answers
  1. Ufuoma
    Ufuoma avatar
    5 posts
    Member since:
    Nov 2012

    Posted 30 Nov 2012 Link to this post

    Please how can I change the color of the bars of the telerik barchart.

    Thanks.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Nov 2012 Link to this post

    Hi,

    Please check the following code snippet I tried to assign different colors for the Bar Chart.

    ASPX:
    <telerik:RadChart ID="RadChart1" SkinsOverrideStyles="true" runat="server">
        <PlotArea>
            <XAxis MaxValue="5" MinValue="1" Step="1">
            </XAxis>
            <YAxis MaxValue="3" Step="0.5" AxisMode="Extended">
            </YAxis>
            <YAxis2 MaxValue="5" MinValue="1" Step="1">
            </YAxis2>
        </PlotArea>
        <Series>
            <telerik:ChartSeries Name="Series 1">    
                <Items>
                    <telerik:ChartSeriesItem YValue="1" Name="Item 1">
                    </telerik:ChartSeriesItem>
                    <telerik:ChartSeriesItem YValue="2" Name="Item 2">
                    </telerik:ChartSeriesItem>
                    <telerik:ChartSeriesItem YValue="1" Name="Item 3">
                    </telerik:ChartSeriesItem>
                    <telerik:ChartSeriesItem YValue="3" Name="Item 4">
                    </telerik:ChartSeriesItem>
                    <telerik:ChartSeriesItem YValue="2" Name="Item 5">
                    </telerik:ChartSeriesItem>
                </Items>
            </telerik:ChartSeries>
        </Series>
    </telerik:RadChart>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        Color[] barColors = new Color[5]{
        Color.Purple,
        Color.Red,
        Color.Aqua,
        Color.Yellow,
        Color.Green
    };
    if (!IsPostBack)
    {
        int i = 0;
        foreach (ChartSeriesItem item in RadChart1.Series[0].Items)
        {
            item.Appearance.FillStyle.MainColor = barColors[i++];
        }
    }

    Please take a look into this help documentation.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top