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

Pie Chart Custom colors

2 Answers 246 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Neetha
Top achievements
Rank 1
Neetha asked on 21 May 2014, 09:58 PM
I have a piechart, binding data from a storedprocedure. I am getting 2 columns  one is Age and BusinessTotal. Based on Age column data, Color should be showed. Please let me know how to accomplish this.

<telerik:RadHtmlChart runat="server" ID="RadHtmlChart3" Width="300" Height="300" Transitions="true">
                    <Appearance>
                         <FillStyle BackgroundColor="White"></FillStyle>
                    </Appearance>                  
                    <Legend>
                         <Appearance BackgroundColor="White" Position="Right" Visible="false">
                         </Appearance>
                    </Legend>
                    <PlotArea>
                         <Appearance>
                              <FillStyle BackgroundColor="White"></FillStyle>
                         </Appearance>
                         <Series>
                              <telerik:PieSeries DataFieldY="BusinessTotal"  StartAngle="90" >
                                   <LabelsAppearance Visible="false" Position="InsideEnd" DataFormatString="{0:N0}">
                                   </LabelsAppearance>
                                   <TooltipsAppearance Color="White"  DataFormatString="{0:N0}"></TooltipsAppearance>
                         

Databinding : C#
protected void GetBusinessData(string metricName)
        {
                SqlCommand cmdProc = new SqlCommand("[oss].[SelectSalespersonBusinessAge]", SqlConnection);
                cmdProc.CommandType = CommandType.StoredProcedure;
                cmdProc.Parameters.AddWithValue("@LoginName", loginName);
                cmdProc.Parameters.AddWithValue("@MetricYear", metricYear);
                cmdProc.Parameters.AddWithValue("@MetricMonth", metricMonth);

                SqlDataAdapter adp = new SqlDataAdapter();
                adp.SelectCommand = cmdProc;
                adp.Fill(dt);
                RadHtmlChart3.DataSource = dt;
                RadHtmlChart3.DataBind();
                if (dt.Rows[0]["age"].ToString() == "7-12 Months")
                {
                  //Yellow color should be assigned for this part
                  
                }
                if (dt.Rows[1]["age"].ToString() == "12+ Months")
                {
                   //REd for this
                }              
}

2 Answers, 1 is accepted

Sort by
0
Neetha
Top achievements
Rank 1
answered on 22 May 2014, 02:27 PM
Any idea?.. How to accomplish this?
0
Danail Vasilev
Telerik team
answered on 23 May 2014, 08:18 AM
Hello Neetha,

You can use the ColorField property of the series, in order to reference a color for each item from the data source. Such an example is illustrated in the HtmlChart - Conditional Item Colorization online demo.

Regards,
Danail Vasilev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart (Obsolete)
Asked by
Neetha
Top achievements
Rank 1
Answers by
Neetha
Top achievements
Rank 1
Danail Vasilev
Telerik team
Share this question
or