C# 将图表导出到RDLC报告中

C# 将图表导出到RDLC报告中,c#,asp.net,rdlc,C#,Asp.net,Rdlc,我有一个客户有图表的页面。现在需要将此图表放入RDLC报告中。 我已在System.Drawing.image中收集了图表的图像,但不知道如何将其放入RDLC。我将图像绑定到其中一列,然后将其绑定到数据集,以将图像提取到RDLC报告中。 这是代码 DataTable dt = new DataTable(); DataColumn column = new DataColumn("chart"); column.DataType = System.Type.Get

我有一个客户有图表的页面。现在需要将此图表放入RDLC报告中。
我已在System.Drawing.image中收集了图表的图像,但不知道如何将其放入RDLC。

我将图像绑定到其中一列,然后将其绑定到数据集,以将图像提取到RDLC报告中。 这是代码

DataTable dt = new DataTable();
        DataColumn column = new DataColumn("chart");
        column.DataType = System.Type.GetType("System.Byte[]");
        dt.Columns.Add(column);
        DataRow dr = dt.NewRow();

        //Saving the Image of Graph into memory stream
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        Chart1.SaveImage(ms, ChartImageFormat.Png);

        byte[] ByteImage = new byte[ms.Length];
        ms.Position = 0;
        ms.Read(ByteImage, 0, (int)ms.Length);


        dr["chart"] = ByteImage;
        string s = dr[0].ToString();
        dt.Rows.Add(dr);


        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";

        ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",dt));
        ReportViewer1.Visible = true;
        ReportViewer1.LocalReport.Refresh();

我建议如下

  • 为该图表创建RDLC报告,方法是传递用于在该页面上绘制图表的内容。这种方法对您非常有帮助,您可以根据客户的要求对其进行修改

  • 您可以将图像设置为RDLC。使用RDLC图像控件。将图像完整路径传递给将在RDLC报告中使用的数据集


  • 您正在尝试向报表中添加静态图像吗?或者您正在尝试在运行时以编程方式向报表中添加图像?是的,我想添加图像,但我用了其他方法。你能分享一下你能做到的方法吗(作为答案)?