Jump to content
Software FX Community

Chartfx as a webservice to return images


Recommended Posts

I can manage to generate the jpg file by using renderStream directly on the page. 

Basically I use following codes to download the data in excel format from a dataview, any idea I can do similar thing but downloading the image?



Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);

Response.ContentType =

"application/excel";System.IO.StringWriter sw = new System.IO.StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

//Instantiate a datagridSystem.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();

dg.DataSource = dv;


//Tell the datagrid to render itself to htmltextwriter




Link to comment
Share on other sites

HiYou can achieve this with the following approach:

1) Get Chart stream (MyStream) using the chart export method.   MemoryStream MyStream = new MemoryStream();   MyChart.Export(FileFormat.Jpeg, MyStream);   2) Convert the stream to a base 64 string:   MyStream.Position = 0;   StreamReader reader = new StreamReader(MyStream);   string strBase64 = Convert.ToBase64String(MyStream.ToArray());3) Now you can export this base64 string as the output of your webservice endopint.

You can in your excel or any other software, get this base64 str back again into a picture file.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...