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

Telerik reporting : chart is not working in web application

2 Answers 110 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jayaprakash KG
Top achievements
Rank 1
Jayaprakash KG asked on 07 Dec 2009, 06:21 AM

Could you please send me a sample code to bind chart programmatically in web application. It is very urgent.




2 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 07 Dec 2009, 12:44 PM
Hi Jayaprakash KG,

The chart in Telerik Reporting is a report item like all others and as such is used in the Report Designer, so the code for binding it is contained within the report itself. Thus it does not matter what is the application in which the report is being displayed (Win, Web or Silverlight), the chart would be displayed as expected.

As explained in the Chart help topic, if you want to databind the chart item, you need to use the NeedDataSource event and you should work with the processing chart item i.e.:

private void chart1_NeedDataSource(object sender, System.EventArgs e)
   {
     Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
     procChart.DataSource = <your_datasource>;
   }

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Cesar
Top achievements
Rank 1
answered on 05 Jun 2012, 05:13 PM
Hi there,

Im going through a similar situation:
I have a chart inside a report that wont bind at all, iv tried several options

REPORT.DESIGNER.CS===============================================================
 partial class ReportUserCompletion
    {
        #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()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ReportUserCompletion));
            Telerik.Reporting.Charting.ChartAxisItem chartAxisItem1 = new Telerik.Reporting.Charting.ChartAxisItem();
            Telerik.Reporting.Charting.ChartAxisItem chartAxisItem2 = new Telerik.Reporting.Charting.ChartAxisItem();
            Telerik.Reporting.Charting.ChartAxisItem chartAxisItem3 = new Telerik.Reporting.Charting.ChartAxisItem();
            Telerik.Reporting.Charting.ChartAxisItem chartAxisItem4 = new Telerik.Reporting.Charting.ChartAxisItem();
            Telerik.Reporting.Charting.ChartAxisItem chartAxisItem5 = new Telerik.Reporting.Charting.ChartAxisItem();
            Telerik.Reporting.Charting.ChartAxisItem chartAxisItem6 = new Telerik.Reporting.Charting.ChartAxisItem();
            Telerik.Reporting.Charting.ChartAxisItem chartAxisItem7 = new Telerik.Reporting.Charting.ChartAxisItem();
            Telerik.Reporting.Charting.ChartSeries chartSeries1 = new Telerik.Reporting.Charting.ChartSeries();
            Telerik.Reporting.Charting.Styles.Corners corners1 = new Telerik.Reporting.Charting.Styles.Corners();
            Telerik.Reporting.Charting.ChartSeries chartSeries2 = new Telerik.Reporting.Charting.ChartSeries();
            Telerik.Reporting.Charting.Styles.Corners corners2 = new Telerik.Reporting.Charting.Styles.Corners();
            Telerik.Reporting.ReportParameter reportParameter1 = new Telerik.Reporting.ReportParameter();
            Telerik.Reporting.ReportParameter reportParameter2 = new Telerik.Reporting.ReportParameter();
            this.pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection();
            this.pictureBox1 = new Telerik.Reporting.PictureBox();
            this.textBox7 = new Telerik.Reporting.TextBox();
            this.detail = new Telerik.Reporting.DetailSection();
            this.chart1 = new Telerik.Reporting.Chart();
            this.odsReportGraph = new Telerik.Reporting.ObjectDataSource();
            this.pageFooterSection1 = new Telerik.Reporting.PageFooterSection();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            //
            // pageHeaderSection1
            //
            this.pageHeaderSection1.Height = Telerik.Reporting.Drawing.Unit.Cm(4.5D);
            this.pageHeaderSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            this.pictureBox1,
            this.textBox7});
            this.pageHeaderSection1.Name = "pageHeaderSection1";
            //
            // pictureBox1
            //
            this.pictureBox1.Docking = Telerik.Reporting.DockingStyle.Top;
            this.pictureBox1.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Cm(0D), Telerik.Reporting.Drawing.Unit.Cm(0D));
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(19D), Telerik.Reporting.Drawing.Unit.Cm(3.2000997066497803D));
            this.pictureBox1.Sizing = Telerik.Reporting.Drawing.ImageSizeMode.AutoSize;
            this.pictureBox1.Style.BackgroundImage.ImageData = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Style.BackgroundImage.ImageData")));
            this.pictureBox1.Style.BackgroundImage.MimeType = "image/png";
            this.pictureBox1.Style.BackgroundImage.Repeat = Telerik.Reporting.Drawing.BackgroundRepeat.NoRepeat;
            //
            // textBox7
            //
            this.textBox7.Docking = Telerik.Reporting.DockingStyle.Top;
            this.textBox7.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Cm(0D), Telerik.Reporting.Drawing.Unit.Cm(3.2000997066497803D));
            this.textBox7.Name = "textBox7";
            this.textBox7.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(19D), Telerik.Reporting.Drawing.Unit.Cm(0.800000011920929D));
            this.textBox7.Style.Font.Bold = true;
            this.textBox7.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(18D);
            this.textBox7.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
            this.textBox7.Value = "Completion per User";
            //
            // detail
            //
            this.detail.Height = Telerik.Reporting.Drawing.Unit.Cm(8.3999996185302734D);
            this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            this.chart1});
            this.detail.Name = "detail";
            //
            // chart1
            //
            this.chart1.BitmapResolution = 96F;
            this.chart1.ChartTitle.TextBlock.Text = "Progress By Industry Association or Regulatory Body";
            this.chart1.DataSource = this.odsReportGraph;
            this.chart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
            this.chart1.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Cm(0.00010012308484874666D), Telerik.Reporting.Drawing.Unit.Cm(0.00010012308484874666D));
            this.chart1.Name = "chart1";
            this.chart1.PlotArea.XAxis.AutoScale = false;
            this.chart1.PlotArea.XAxis.AxisLabel.Appearance.RotationAngle = 270F;
            this.chart1.PlotArea.XAxis.DataLabelsColumn = "OrgTitle";
            chartAxisItem1.Value = new decimal(new int[] {
            1,
            0,
            0,
            0});
            chartAxisItem2.Value = new decimal(new int[] {
            2,
            0,
            0,
            0});
            chartAxisItem3.Value = new decimal(new int[] {
            3,
            0,
            0,
            0});
            chartAxisItem4.Value = new decimal(new int[] {
            4,
            0,
            0,
            0});
            chartAxisItem5.Value = new decimal(new int[] {
            5,
            0,
            0,
            0});
            chartAxisItem6.Value = new decimal(new int[] {
            6,
            0,
            0,
            0});
            chartAxisItem7.Value = new decimal(new int[] {
            7,
            0,
            0,
            0});
            this.chart1.PlotArea.XAxis.Items.AddRange(new Telerik.Reporting.Charting.ChartAxisItem[] {
            chartAxisItem1,
            chartAxisItem2,
            chartAxisItem3,
            chartAxisItem4,
            chartAxisItem5,
            chartAxisItem6,
            chartAxisItem7});
            this.chart1.PlotArea.XAxis.MinValue = 1D;
            this.chart1.PlotArea.YAxis.AxisLabel.Appearance.RotationAngle = 0F;
            this.chart1.PlotArea.YAxis.AxisMode = Telerik.Reporting.Charting.ChartYAxisMode.Extended;
            this.chart1.PlotArea.YAxis.MaxValue = 100D;
            this.chart1.PlotArea.YAxis.Step = 10D;
            this.chart1.PlotArea.YAxis2.AxisLabel.Appearance.RotationAngle = 0F;
            corners1.BottomRight = Telerik.Reporting.Charting.Styles.CornerType.Round;
            corners1.TopRight = Telerik.Reporting.Charting.Styles.CornerType.Round;
            chartSeries1.Appearance.Corners = corners1;
            chartSeries1.Appearance.FillStyle.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(213)))), ((int)(((byte)(247)))), ((int)(((byte)(255)))));
            chartSeries1.DataXColumn = "OrgLimit";
            chartSeries1.DefaultLabelValue = "CPD Goal";
            chartSeries1.Name = "Series 1";
            corners2.BottomRight = Telerik.Reporting.Charting.Styles.CornerType.Round;
            corners2.TopRight = Telerik.Reporting.Charting.Styles.CornerType.Round;
            chartSeries2.Appearance.Corners = corners2;
            chartSeries2.Appearance.FillStyle.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(218)))), ((int)(((byte)(254)))), ((int)(((byte)(122)))));
            chartSeries2.DataXColumn = "MyScore";
            chartSeries2.DefaultLabelValue = "My Score";
            chartSeries2.Name = "Series 2";
            this.chart1.Series.AddRange(new Telerik.Reporting.Charting.ChartSeries[] {
            chartSeries1,
            chartSeries2});
            this.chart1.SeriesOrientation = Telerik.Reporting.Charting.ChartSeriesOrientation.Horizontal;
            this.chart1.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(19D), Telerik.Reporting.Drawing.Unit.Cm(7.5D));
            this.chart1.NeedDataSource += new System.EventHandler(this.chart1_NeedDataSource);
            //
            // odsReportGraph
            //
            this.odsReportGraph.DataMember = "ReportSelectUserDataByOrganization";
            this.odsReportGraph.DataSource = typeof(CPDOne.Warehouse.ReportFactory);
            this.odsReportGraph.Name = "odsReportGraph";
            this.odsReportGraph.Parameters.AddRange(new Telerik.Reporting.ObjectDataSourceParameter[] {
            new Telerik.Reporting.ObjectDataSourceParameter("UserId", typeof(long), "=Parameters.UserId.Value"),
            new Telerik.Reporting.ObjectDataSourceParameter("needId", typeof(bool), "=Parameters.needId.Value")});
            //
            // pageFooterSection1
            //
            this.pageFooterSection1.Height = Telerik.Reporting.Drawing.Unit.Cm(3D);
            this.pageFooterSection1.Name = "pageFooterSection1";
            //
            // ReportUserCompletion
            //
            this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            this.pageHeaderSection1,
            this.detail,
            this.pageFooterSection1});
            this.Name = "ReportUserCompletion";
            this.PageSettings.Landscape = false;
            this.PageSettings.Margins.Bottom = Telerik.Reporting.Drawing.Unit.Cm(1D);
            this.PageSettings.Margins.Left = Telerik.Reporting.Drawing.Unit.Cm(1D);
            this.PageSettings.Margins.Right = Telerik.Reporting.Drawing.Unit.Cm(1D);
            this.PageSettings.Margins.Top = Telerik.Reporting.Drawing.Unit.Mm(1D);
            this.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.A4;
            reportParameter1.Name = "UserId";
            reportParameter1.Text = "UserId";
            reportParameter1.Type = Telerik.Reporting.ReportParameterType.Integer;
            reportParameter2.Name = "needId";
            reportParameter2.Text = "needId";
            reportParameter2.Type = Telerik.Reporting.ReportParameterType.Boolean;
            this.ReportParameters.Add(reportParameter1);
            this.ReportParameters.Add(reportParameter2);
            this.Style.BackgroundColor = System.Drawing.Color.White;
            this.Width = Telerik.Reporting.Drawing.Unit.Cm(19D);
            this.NeedDataSource += new System.EventHandler(this.ReportUserCompletion_NeedDataSource);
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();

        }
        #endregion

        private Telerik.Reporting.PageHeaderSection pageHeaderSection1;
        private Telerik.Reporting.DetailSection detail;
        private Telerik.Reporting.PageFooterSection pageFooterSection1;
        private Telerik.Reporting.PictureBox pictureBox1;
        private Telerik.Reporting.TextBox textBox7;
        private Telerik.Reporting.Chart chart1;
        private Telerik.Reporting.ObjectDataSource odsReportGraph;
    }


REPORT.CS===============================================================
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;

    /// <summary>
    /// Summary description for ReportUserCompletion.
    /// </summary>
    public partial class ReportUserCompletion : Telerik.Reporting.Report
    {
        public ReportUserCompletion()
        {
            //
            // Required for telerik Reporting designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        private void chart1_NeedDataSource(object sender, EventArgs e)
        {
            //odsReportGraph.Parameters["needId"].Value = this.ReportParameters["needId"].Value;
            //odsReportGraph.Parameters["UserId"].Value = this.ReportParameters["UserId"].Value;
            //chart1.DataSource = odsReportGraph;

            ReportFactory _ReportFactory = new ReportFactory();
            chart1.DataSource = _ReportFactory.ReportSelectUserDataByOrganization(Int64.Parse(this.ReportParameters["UserId"].Value.ToString()));

        }

        private void ReportUserCompletion_NeedDataSource(object sender, EventArgs e)
        {

            ReportFactory _ReportFactory = new ReportFactory();
            chart1.DataSource = _ReportFactory.ReportSelectUserDataByOrganization(Int64.Parse(this.ReportParameters["UserId"].Value.ToString()));
            //this.DataSource = _ReportFactory.ReportSelectUserDataByOrganization(Int64.Parse(this.ReportParameters["UserId"].Value.ToString()));
        }
    }

MY_WEB_APP.ASPX ===============================================================
here is where i load the variables and pass onto the report and subsequently to the datasource inside the report that loads the graph:
// this is my dataobject
       CPDOne.Warehouse.ReportUserCompletion _ReportUSerCompletion = new ReportUserCompletion();
        _ReportUSerCompletion.ReportParameters["UserId"].Value = UserId;
        _ReportUSerCompletion.ReportParameters["needId"].Value = true;
        ReportViewer1.Report = _ReportUSerCompletion;


Please help me, what am i doing wrong, i need to bind data to this chart inside the report. thanks in advance.

Tags
General Discussions
Asked by
Jayaprakash KG
Top achievements
Rank 1
Answers by
Steve
Telerik team
Cesar
Top achievements
Rank 1
Share this question
or