Welcome Guest Search | Active Topics |

Export to Image
Pooya
#1 Posted : Tuesday, January 31, 2012 4:05:30 AM(UTC)
Rank: Member

Groups: Registered
Joined: 9/17/2011(UTC)
Posts: 23

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
Hi,


Is there any way to Export 3 jqchart to One Single image?
I need this to export financial chart and my chart has 3 jqchart (HLOC , Volume , and 1 or more Indicator like RSI...)


Thanks
Pooya
Dragan
#2 Posted : Tuesday, January 31, 2012 2:14:12 PM(UTC)
Rank: Advanced Member

Groups: Administrators, DataVizJavaScript, jQueryChart, jQueryDV, MvcChart, Registered
Joined: 1/3/2011(UTC)
Posts: 483

Thanks: 0 times
Was thanked: 87 time(s) in 87 post(s)
Hi,

Unfortunately, currently we’re not providing such functionality.

Probably you can try combining the 3 images from the charts into one on the server.
Best Regards,
Dragan Matek
jqChart Inc.
Pooya
#3 Posted : Saturday, February 4, 2012 7:51:07 AM(UTC)
Rank: Member

Groups: Registered
Joined: 9/17/2011(UTC)
Posts: 23

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
Hi

I wrote little code to do this job. I post it here.

Pooya



Server Side Code:

private void GenerateChart()
{

string[] source = Request.Form["s"].Split(',');

Image[] ImageSource= new Image[source.Length];

for (int ipos = 0; ipos < source.Length; ipos++)
{
ImageSource[ipos] = Base64ToImage(source[ipos]);
}

int OutputHeight=0;
int OutputWidth=ImageSource[0].Width;

for (int ipos = 0; ipos < source.Length; ipos++)
{
OutputHeight += ImageSource[ipos].Height;
}

var target = new Bitmap(OutputWidth, OutputHeight, PixelFormat.Format32bppArgb);
var graphics = Graphics.FromImage(target);

int Top = 0;
for (int ipos = 0; ipos < source.Length; ipos++)
{
graphics.DrawImage(ImageSource[ipos], 0, Top);
Top += ImageSource[ipos].Height;
}

Response.ClearHeaders();

string base64;
MemoryStream memory =new MemoryStream();
target.Save(memory, ImageFormat.Png);
base64 = Convert.ToBase64String(memory.ToArray());
memory.Close();
memory = null;

Response.Write(base64);
}

private Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);

// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
return image;
}


Client Side Code:
function ExportToImage(ParentDiv) {
var base64="";

var charts=$(ParentDiv + " canvas");
var no=charts.length;

var ipos;
for (ipos = 0; ipos < no; ipos++) {
alert(charts[ipos].toDataURL("image/png").split(',')[0]);
base64 += charts[ipos].toDataURL("image/png").split(',')[1];

if (ipos < no - 1) base64 += ",";
}

$.ajax({
url: "tsev2/chart/img/merge.aspx",
type: "POST",
cache: false,
dataType: "text",
data: { s: base64 },
success: function (data) {
var Result='data:image/png;base64,' + data;

// Use Result in your code
}
});

}
Pooya
#4 Posted : Sunday, February 5, 2012 3:34:06 AM(UTC)
Rank: Member

Groups: Registered
Joined: 9/17/2011(UTC)
Posts: 23

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
Hi

If anyone need to Export many charts to one images and save them (open save dialog of browser), I changed client side script:

function ExportToImage(ParentDiv) {
var base64="";

var charts=$(ParentDiv + " canvas");
var no=charts.length;

var ipos;
for (ipos = 0; ipos < no; ipos++) {
base64 += charts[ipos].toDataURL("image/png").split(',')[1];
if (ipos < no - 1) base64 += ",";
}

$('<form action="/tsev2/chart/img/merge.aspx" method="post"><input type="hidden" name="s" value="' + base64 + '" /></form>').appendTo('body').submit().remove();

}


and server side:

private void GenerateChart()
{
string[] source = Request.Form["s"].Split(',');

Image[] ImageSource= new Image[source.Length];

for (int ipos = 0; ipos < source.Length; ipos++)
{
ImageSource[ipos] = Base64ToImage(source[ipos]);
}

int OutputHeight=0;
int OutputWidth=ImageSource[0].Width;

for (int ipos = 0; ipos < source.Length; ipos++)
{
OutputHeight += ImageSource[ipos].Height;
}

var target = new Bitmap(OutputWidth, OutputHeight, PixelFormat.Format32bppArgb);
var graphics = Graphics.FromImage(target);

int Top = 0;
for (int ipos = 0; ipos < source.Length; ipos++)
{
graphics.DrawImage(ImageSource[ipos], 0, Top);
Top += ImageSource[ipos].Height;
}

Response.ClearHeaders();
Response.AddHeader("content-disposition", "attachment;filename=chart.png");
Response.ContentType = "image/png";

target.Save(Response.OutputStream, ImageFormat.Png);

//string base64;
//MemoryStream memory =new MemoryStream();
//target.Save(memory, ImageFormat.Png);
//base64 = Convert.ToBase64String(memory.ToArray());
//memory.Close();
//memory = null;

//Response.Write(base64);
}
Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

FlatEarth Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.176 seconds.