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

chart in grid

1 Answer 43 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Jelena Nahaja
Top achievements
Rank 1
Jelena Nahaja asked on 03 Mar 2011, 09:10 PM
I  have "CHART_COLUMN" in grid and need to able to export grid  to .pdf as image.Problem is a chart.
 I saved chart as .jpeg. Could you check my code. I appreciate any help or resources.

    RadChart chart = (RadChart)item["CHART_COLUMN"].FindControl("RadChart1");
                SetChart(chart, item);
                MemoryStream imageStream = new MemoryStream();
                chart.Save(imageStream, ImageFormat.Jpeg);
                Byte[] imageContent = new Byte[imageStream.Length];
                imageStream.Position = 0;
                Response.ContentType = "image/gif";
                imageStream.Read(imageContent, 0, (Int32)imageStream.Length);
                imageStream.Close();


                RadBinaryImage rbi = (RadBinaryImage)item["chartimage"].FindControl("RadBinaryImage1");
                if (rbi != null)
                {
                    rbi.DataValue = (Byte[])imageContent;
                   // rbi.DataBind();


                }

1 Answer, 1 is accepted

Sort by
0
Jelena Nahaja
Top achievements
Rank 1
answered on 04 Mar 2011, 03:28 PM
I was able to resolve it
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
.........................some code here....................................
 RadChart chart = (RadChart)item["CHART_COLUMN"].FindControl("RadChart1");
                SetChart(chart, item);
                MemoryStream imageStream = new MemoryStream();
                chart.Save(imageStream, ImageFormat.Jpeg);
                Byte[] imageContent = new Byte[imageStream.Length];
                imageStream.Position = 0;
                imageStream.Read(imageContent, 0, (Int32)imageStream.Length);
                RadBinaryImage rbi = (RadBinaryImage)item["chartimage"].FindControl("RadBinaryImage1");
                if (rbi != null)
                {
                    rbi.DataValue = imageContent;
                    rbi.DataBind();

                }
}
Tags
BinaryImage
Asked by
Jelena Nahaja
Top achievements
Rank 1
Answers by
Jelena Nahaja
Top achievements
Rank 1
Share this question
or