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

Showing actual value and percentage in Pie Chart

1 Answer 601 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michelle
Top achievements
Rank 1
Michelle asked on 27 Jul 2012, 04:12 AM
Hi,

I'm using Radchart in winform to databind to a generic list. How can I show both the Percentage and actual value as the label?

Attached is the desired output.

Below is the sample data

columnname valuedata
< 20 days 112
<= 50 days 532
<= 90 days 40
> 90 days 168

Codes
protected void CreateChart()
        {
            RadChart chartObj = new RadChart();
            chartObj.SkinsOverrideStyles = false;
            chartObj.ChartTitle.TextBlock.Text = "No of Items";
            chartObj.Size = new Size(800, 600);
            chartObj.ItemDataBound += new EventHandler<ChartItemDataBoundEventArgs>(chartObj_ItemDataBound);
            chartObj.DataManager.DataSource = _objBLL.GetData();
            chartObj.DataManager.LabelsColumn = "ColumnName";
            chartObj.IntelligentLabelsEnabled = true;
            chartObj.DataBind();
            chartObj.Series[0].Type = ChartSeriesType.Pie;
            chartObj.Series[0].Name = "Days";
            chartObj.Series[0].Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
            chartObj.Update();
  
            this.Controls.Add(chartObj);
  
        }
  
        protected void chartObj_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
        {
            if (e.SeriesItem != null)
            {
                DataRowView dtView = e.DataItem as DataRowView;
  
                if (dtView != null)
                {
                    e.SeriesItem.Label.TextBlock.Text = string.Format("{0}%", dtView["ChartValue"]);
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Evgenia
Telerik team
answered on 27 Jul 2012, 10:45 AM
Hi Michelle,

 Actually you almost did it in your ItemDataBound event. You'll just need to append the value to the formatted one :

void RadChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
  {
      if (e.SeriesItem != null)
      {
          DataRowView dtView = e.DataItem as DataRowView;
          if (dtView != null)
          {
              e.SeriesItem.Label.TextBlock.Text = string.Format("{0}%", dtView["ChartValue"]) + " " + dtView["ChartValue"];
          }
      
  }

I hope this helps.

All the best,
Evgenia
the Telerik team

RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
Chart (obsolete as of Q1 2013)
Asked by
Michelle
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or