Showing actual value and percentage in Pie Chart

2 posts, 1 answers
  1. Michelle
    Michelle avatar
    7 posts
    Member since:
    May 2012

    Posted 26 Jul 2012 Link to this post

    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"]);
                    }
                }
            }

  2. Answer
    Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 27 Jul 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top