+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Display Poll results as Percentage?

Display Poll results as Percentage?

6 posts, 1 answered
  1. CWaters
    CWaters avatar
    15 posts
    Registered:
    04 May 2010
    19 Jul 2010
    Link to this post
    Can I display the results for a poll in percentage instead of a raw count?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Jul 2010
    Link to this post
    Hello CWaters,

    By default ResultBox control shows results in percentage. Sample video has been attached.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. CWaters
    CWaters avatar
    15 posts
    Registered:
    04 May 2010
    20 Jul 2010
    Link to this post
    Thanks for the video. What I want to do is have the results display with a vertical bar graph that includes the percentage at the top.

    Right now at the end of the bar on the graph it shows a number of the votes, I'd rather have this as a percentage and just show the answer below it.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Jul 2010
    Link to this post
    Hello CWaters,

    You need to create a custom control that inherits from Telerik.Polls.WebControls.ResultsBox.  There you should override CreateRadChart method. Here you have to build the series.


    protected override Telerik.Web.UI.RadChart CreateRadChart()
      {
          RadChart chart = new RadChart();
     
          // RadChart settings.
          chart.ID = "answerChart";
          chart.EnableViewState = false;
          chart.Legend.Visible = false;
          chart.ChartTitle.Visible = false;
          chart.SeriesOrientation = ChartSeriesOrientation.Vertical;
          chart.Width = this.BarsWidth;
          chart.Height = this.BarsHeight;
          chart.UseSession = false;
          chart.TempImagesFolder = ResultsBox.PollsTempDir;
          chart.Appearance.Border.Visible = false;
          chart.Appearance.Border.Color = Color.Transparent;
          chart.Appearance.BarWidthPercent = 100;
         
          // PlotArea settings.
          chart.PlotArea.Appearance.Dimensions.Margins.Bottom = Telerik.Charting.Styles.Unit.Pixel(0);
          chart.PlotArea.Appearance.Dimensions.Margins.Top = Telerik.Charting.Styles.Unit.Pixel(0);
          chart.PlotArea.Appearance.Dimensions.Margins.Right = Telerik.Charting.Styles.Unit.Pixel(0);
          chart.PlotArea.Appearance.Dimensions.Margins.Left = Telerik.Charting.Styles.Unit.Pixel(0);
          chart.PlotArea.XAxis.Visible = Telerik.Charting.Styles.ChartAxisVisibility.False;
          chart.PlotArea.Appearance.Border.Visible = false;
          chart.PlotArea.Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Solid;
          chart.PlotArea.Appearance.FillStyle.MainColor = Color.Transparent;
     
          chart.Series.Add(new ChartSeries());
          chart.Series[0].Items.Add(new ChartSeriesItem());
          chart.Series[0].Appearance.ShowLabels = ShowSeriesLabels;
     
          return chart;
      }

    Then you have to set SetItemLabel of the Series to vote percentage. To do this you have to rebind the ResultsBox repeater  inside CreateChildControls

    sample

    private void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
          {
              if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
              {
                  Panel panel = e.Item.FindControl("chartPanel") as Panel;
     
                  if (panel != null)
                  {
                      RadChart chart = this.CreateRadChart();
                      panel.Controls.Add(chart);
                   
                      if (chart.Series.Count == 0 || chart.Series[0].Items.Count == 0)
                      {
                          throw new NotSupportedException(String.Format(Messages.NoItemInChart, "answerChart"));
                      }
                      
                      IAnswerItem answer = (IAnswerItem)e.Item.DataItem;
                      if (answer != null)
                      {
                          ITextControl percentage = e.Item.FindControl("percentage") as ITextControl;
                          if (percentage != null)
                          {
                              percentage.Text = String.Format(this.PercentageFormat, answer.Percentage);
                          }
     
                          chart.Series[0].SetItemLabel(0, answer.Percentage.ToString());
                         // chart.Series[0].SetValues(new double[1] { (double)answer.VoteCount });                       
                          chart = this.SetChartColors(chart, answer);                       
                      }
                  }
              }
          }


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. CWaters
    CWaters avatar
    15 posts
    Registered:
    04 May 2010
    27 Jul 2010
    Link to this post
    Ivan,

    Thanks for the help. I'm having a little trouble with the last part though. How do I rebind the ResultsBox Repeater inside CreateChildControls?

    If it helps, I'm trying to do this in VB.NET.

    Thanks!
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Jul 2010
    Link to this post
    Hello CWaters,

    In CreateChildControls you have to set the Repeater datasource , subscribe for ItemDataBound and bind the Repeater.

    this.QuestionList.ItemDataBound += new RepeaterItemEventHandler(QuestionList_ItemDataBound);
    this.QuestionList.DataSource = poll.Questions;
    this.QuestionList.DataBind();


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 1 answered