saving images
FusionCharts Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        


«««12345»»»

saving images Expand / Collapse
Author
Message
Posted 1/21/2008 10:54:46 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 1/21/2008 10:43:07 AM
Posts: 1, Visits: 1
If you're cool with PNGs, here's some Ruby code to take the FusionCharts data and return it as a PNG. Please let me know if you find any bugs in it, but it's been working well for me so far. I have this saved in my controllers as graph_controller.rb


# * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# * FusionChartsSave for Ruby on Rails (Jan 21 2008)
# * Requires PNG gem from http://seattlerb.rubyforge.org/
# * PNG is an almost-pure-ruby PNG library.
# *
# * sudo gem install -y png
# *
# * The default location for the imageSaveURL would be:
# * imageSaveURL='/graph/imagesave'
# * * * * * * * * * * * * * * * * * * * * * * * * * * * *
require 'png'

class GraphController < ApplicationController

def imagesave
#### Prevent Memory abuse
maxwidth = 1024
maxheight = 1024

width = params[:width].to_i
height = params[:height].to_i
bgcolor = params[:bgcolor]
cdata = params[:data]

if width > maxwidth
return nil
end
if height > maxheight
return nil
end

if bgcolor.nil?
bgcolor = PNG::Color::Background
else
bgcolor = PNG::Color.from "0x#{bgcolor.rjust(6,'0')}FF"
end

canvas = PNG::Canvas.new width, height, bgcolor

# Keep count of which row we are on in our loop. Start on the top and draw down.
ycount = height - 1

rows = cdata.split(";")

rows.each do |row|
### Reset the count for each new row
ri = 0

pixels = row.split(",")
pixels.each do |pixel|
c,r = pixel.split("_")

if c.length > 0
x = 0
mycolor = PNG::Color.from "0x#{c.rjust(6,'0')}FF"
while x < r.to_i
#point function will prevent drawing outside of canvas
canvas.point(ri + x, ycount, mycolor)
x += 1
end
end

ri += r.to_i
end

#Move down to the next row
ycount -= 1
end

png = PNG.new canvas
send_data(png.to_blob, {:type => "content-type:image/png", :stream => true, :filename => "FusionCharts.png"})

end

end
Post #3992
Posted 1/24/2008 1:38:25 PM
FusionCharts Team

FusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts Team

Group: Administrators
Last Login: Today @ 12:15:43 AM
Posts: 2,228, Visits: 540
Hi,

Thanks for sharing this code. I was wondering if you would allow us to publish this in our documentation.


Thanks,
Pallav Nadhani
FusionCharts Team
Post #4069
Posted 3/5/2008 3:35:33 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/5/2008 6:35:30 AM
Posts: 1, Visits: 3
Hi, Are you able to help?

I am trying to save a chart and when I click on the "Save as Image" option on the chart, it runs through the sequence "Capturing Data" until it reaches 100% but then the browser goes on to display the "Image Saving" file (eg. FusionChartsSave.aspx) I set the URL to?

I have tried different image saving files with no success.

An example of what appears in the browser if I use FusionChartsSave.aspx...

<%@ Page Inherits="FusionChartsSave" Src="FusionChartsSave.cs" Debug="true" validateRequest="false" %>
There seems to be an error with the "validaterequest" field.
I think Fusionchart is a great tool and would really appreciate any help.
Thanks in advance. James
Post #4931
Posted 3/6/2008 12:28:33 PM
FusionCharts Team

FusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts TeamFusionCharts Team

Group: Administrators
Last Login: Today @ 12:15:43 AM
Posts: 2,228, Visits: 540
James,

Is there any security setting in your IIS that disallows large POST headers?


Thanks,
Pallav Nadhani
FusionCharts Team
Post #4969
Posted 3/14/2008 1:46:01 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/14/2008 3:15:04 PM
Posts: 6, Visits: 14
Hi,

I'm trying to use the posted Ruby code, but I'm having trouble getting RubyInline to work on my windows machine. Is there anyone who can help

me get this code working on a windows machine? ie. maybe a walk-through of how you got it working.
Post #5088
Posted 3/28/2008 4:25:23 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/10/2008 8:22:31 AM
Posts: 5, Visits: 15
i have the same problem as yumi001

But then I changed the file from .aspx to .jsp. Now I can save the image, but it looks like crap. For example the Xaxisname isn't displayed.

How do u solve this?
Post #5308
Posted 4/10/2008 1:42:24 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 4/14/2008 4:09:10 PM
Posts: 2, Visits: 5
Some more information regarding the PNG/Ruby implementation would be great. I was wondering how you are calling the action in that controller and where the params are coming from, especially the 'cdata' object with all the pixelvalues.

could you maybe elaborate on how you go from a FusionChart to this piece of Ruby code?

Post #5562
Posted 4/11/2008 2:21:08 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 12/15/2008 2:00:28 AM
Posts: 18, Visits: 24
hello folks

there are so many people out there which have the same problem: render image file from swf on the server.

i found a way to do this!!! i will implement it in the next few days and will share my work with you.

hold on some days
Post #5572