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

Pie Chart in Report Cropped

3 Answers 131 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 12 Apr 2012, 03:25 PM
I am trying to add a Pie Chart to a Telerik report for the first time and I am having an issue with that chart being cropped on the right-hand side just after the legend starts.  I have included a screen image of the issue.  

I have added the pie chart through the design interface and I am populating the data the the OnNeedData event.  Below is that code.  

private void PieChart_NeedDataSource(object sender, System.EventArgs e)
 {
            //Charts - Columns to Display
            string[] GraphColumnsToExport = new string[2] { "ShortLegendTitle", "Data" };
 
            //Charts
            DataTable Total = _SharedDataSet.Tables["CurrentYearToDate"].DefaultView.ToTable("tempTableName", false, GraphColumnsToExport);
 
            //Set the Series
            Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
            Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
            ChartSeries serie = new ChartSeries();
            serie.Type = ChartSeriesType.Pie;
            serie.Clear();
             
 
            foreach (DataRow dr in Total.Rows)
            {
                ChartSeriesItem item = new ChartSeriesItem();
                item.Label.Visible = true;
                item.YValue = Convert.ToDouble(dr["Data"]);
                item.Name = Convert.ToString(dr["ShortLegendTitle"]);
                item.Appearance.Exploded = false;
                item.Label.TextBlock.Text = item.Name + " - #%";
                serie.Items.Add(item);
                 
            }
            serie.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
            defChart.Series.Add(serie);
}

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 12 Apr 2012, 04:05 PM
Hi David,

The code you've provided is correct so the problem must be caused by something else. Please try resizing the chart i.e. making it bigger if your report layout allows it. Another thing to try is set its AutoLayout property to True and see if that makes any difference.
On a side note, does the same issue occur in any of the export formats e.g. PDF?

If you're still having problems, please provide us with a runnable report that exhibits the problem and we would advise you accordingly.

Kind regards,
Steve
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
0
david
Top achievements
Rank 1
answered on 12 Apr 2012, 05:50 PM
Steve,
I have tried everything you suggested with no luck, although the pie chart does display correctly in the PDF.

 I've have created a new project with just the aspx page with a report viewer and the report. 

Below is the code:

Default.cs.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
  
namespace TelerikPieChartTest
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ShortLegendTitle", typeof(String));
            dt.Columns.Add("Data", typeof(Decimal));
  
            dt.Rows.Add("Spec. Commercial",68.624);
            dt.Rows.Add("Middle Market",131.938);
            dt.Rows.Add("Personal Lines", 53.453);
            dt.Rows.Add("Small Commercial", 542.864);
  
            PieChartTest report = new PieChartTest(dt);
            reportViewer.Report = report;
            reportViewer.RefreshReport();
        }
    }
}

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikPieChartTest._Default" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=5.3.12.119, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>
  
<head runat="server">
    <title>Pie Chart Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:ReportViewer ID="reportViewer" runat="server"
            Width="710px"
            Height="800px"></telerik:ReportViewer>
    </div>
    </form>
</body>
</html>


Report: PieChartTest.cs
namespace TelerikPieChartTest
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Data;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;
    using Telerik.Reporting.Charting;
  
    /// <summary>
    /// Summary description for PieChartTest.
    /// </summary>
    public partial class PieChartTest : Telerik.Reporting.Report
    {
        #region Properties
        private DataTable _dt = new DataTable();
        #endregion Properties
  
        #region Constructor
        public PieChartTest(DataTable dt)
        {
            InitializeComponent();
            _dt = dt;
            if (_dt.Rows.Count > 0)
            {
                //Pie Chart
                this.PieChart.NeedDataSource += new System.EventHandler(this.PieChart_NeedDataSource);
            }
        }
        #endregion Constructor
  
        #region Private Methods
        private void PieChart_NeedDataSource(object sender, System.EventArgs e)
        {
            //Charts - TWP ($)
            DataTable twpTotal = _dt;
  
            //Defines the Chart
            Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
            Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
  
            //Sets the chart borders
            defChart.Appearance.Border.Visible = true;
            defChart.Appearance.Border.Width = 3;
            defChart.Appearance.Border.Color = Color.Red;
  
            //Layout
            defChart.AutoLayout = true;
  
            //Sets the Labels
            defChart.IntelligentLabelsEnabled = true;
  
            //Set the Series
            ChartSeries serie = new ChartSeries();
            serie.Type = ChartSeriesType.Pie;
            serie.Clear();
  
            foreach (DataRow rowView in twpTotal.Rows)
            {
                ChartSeriesItem seriesItem = new ChartSeriesItem();
                //item.XValue = Convert.ToDouble(dr["Data"]);
                seriesItem.Label.Visible = true;
                seriesItem.YValue = Convert.ToDouble(rowView["Data"]);
                seriesItem.Name = Convert.ToString(rowView["ShortLegendTitle"]);
                seriesItem.Appearance.Exploded = false;
                seriesItem.Label.TextBlock.Text = seriesItem.Name + " - #%";
                serie.Items.Add(seriesItem);
  
                serie.AddItem(seriesItem);
            }
  
            //Display the legend
            serie.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
            serie.Appearance.Border.Color = System.Drawing.Color.White;
            serie.Appearance.Border.Visible = false;
            serie.Appearance.DiameterScale = .90;
            //serie.Appearance.ExplodePercent = 10;
  
            defChart.Series.Clear();
            defChart.Series.Add(serie);
            defChart.Legend.Appearance.Position.AlignedPosition = Telerik.Reporting.Charting.Styles.AlignedPositions.TopRight;
  
        }
  
        #endregion Private Methods
    }
}

Report: PieChartTest.Designer
namespace TelerikPieChartTest
{
    partial class PieChartTest
    {
        #region Component Designer generated code
        /// <summary>
        /// Required method for telerik Reporting designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection();
            this.detail = new Telerik.Reporting.DetailSection();
            this.pageFooterSection1 = new Telerik.Reporting.PageFooterSection();
            this.PieChart = new Telerik.Reporting.Chart();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            // 
            // pageHeaderSection1
            // 
            this.pageHeaderSection1.Height = Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224);
            this.pageHeaderSection1.Name = "pageHeaderSection1";
            // 
            // detail
            // 
            this.detail.Height = Telerik.Reporting.Drawing.Unit.Inch(3.5);
            this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            this.PieChart});
            this.detail.Name = "detail";
            // 
            // pageFooterSection1
            // 
            this.pageFooterSection1.Height = Telerik.Reporting.Drawing.Unit.Inch(0.30000001192092896);
            this.pageFooterSection1.Name = "pageFooterSection1";
            // 
            // PieChart
            // 
            this.PieChart.BitmapResolution = 120F;
            this.PieChart.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
            this.PieChart.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.40000000596046448), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224));
            this.PieChart.Name = "PieChart";
            this.PieChart.PlotArea.EmptySeriesMessage.Appearance.Visible = true;
            this.PieChart.PlotArea.EmptySeriesMessage.Visible = true;
            this.PieChart.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(3.2999999523162842), Telerik.Reporting.Drawing.Unit.Inch(3.0999999046325684));
            // 
            // PieChartTest
            // 
            this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            this.pageHeaderSection1,
            this.detail,
            this.pageFooterSection1});
            this.PageSettings.Margins.Bottom = Telerik.Reporting.Drawing.Unit.Inch(1);
            this.PageSettings.Margins.Left = Telerik.Reporting.Drawing.Unit.Inch(1);
            this.PageSettings.Margins.Right = Telerik.Reporting.Drawing.Unit.Inch(1);
            this.PageSettings.Margins.Top = Telerik.Reporting.Drawing.Unit.Inch(1);
            this.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Letter;
            this.Style.BackgroundColor = System.Drawing.Color.White;
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
  
        }
        #endregion
  
        private Telerik.Reporting.PageHeaderSection pageHeaderSection1;
        private Telerik.Reporting.DetailSection detail;
        private Telerik.Reporting.PageFooterSection pageFooterSection1;
        private Telerik.Reporting.Chart PieChart;
    }
}

Thanks.

David
0
Elian
Telerik team
answered on 17 Apr 2012, 02:32 PM
Hi David,

We will need some more time to further look into this issue. Meanwhile, if you have any other questions, you can ask them in the support ticket system, as we noticed that there is an open discussion on a matter similar to the current. Threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

Kind regards,
Elian
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
david
Top achievements
Rank 1
Answers by
Steve
Telerik team
david
Top achievements
Rank 1
Elian
Telerik team
Share this question
or