Class: JfreechartChart

Inherits:
BaseChart show all
Defined in:
lib/libisi/chart/jfreechart.rb

Constant Summary

Constants inherited from BaseChart

BaseChart::BAR_TYPES, BaseChart::DEFAULT_CHART_TYPE, BaseChart::DEFAULT_HEIGHT, BaseChart::DEFAULT_LEGEND_CHART_RATIO, BaseChart::DEFAULT_LEGEND_ROTATION, BaseChart::DEFAULT_STACKED, BaseChart::DEFAULT_WIDTH

Instance Attribute Summary

Attributes inherited from BaseChart

#height, #legend_chart_ratio, #legend_rotation, #stacked, #title, #type, #width

Instance Method Summary collapse

Methods inherited from BaseChart

#create_chart, #create_combined_plot, #create_plot, #data_dimension, #display_legend, #enable_tooltips, #enable_urls, #initialize, #load, #mark, #orientation, #range, #ranges, #save, #serie, #time_span, #value, #xaxis, #xaxis=, #yaxis, #yaxis=, #zaxis, #zaxis=

Constructor Details

This class inherits a constructor from BaseChart

Instance Method Details

#data(mime_type, options = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/libisi/chart/jfreechart.rb', line 108

def data(mime_type, options = {})
  raise "No chart defined" unless @chart

  temp_file {|temp_image_file|
    info = ChartRenderingInfo.new(StandardEntityCollection.new)
    ChartUtilities.saveChartAsPNG(JFile.new(temp_image_file.to_s),
		      @chart, width.to_i, height.to_i, info);
    
    case mime_type
    when "image/png"
	temp_image_file.open("r").read
    when "text/html"
	image_file = nil
	image_file = Pathname.new(options[:image_file]) if
 image_file.nil? and options[:image_file]
	image_file = Pathname.new(image_path) + "jfreechart.png" if 
 image_file.nil? and options[:image_path]

	image_map_file = nil
	image_map_file = Pathname.new(option[:image_map_file]) if
 image_map_file.nil? and options[:image_map_file]
	
	image_map_file.open("w") {|f|
 f.write(ChartUtilities.getImageMap("chart", info))
	} if image_map_file
	
	
	html_file = StringIO.new      
	# write an HTML page incorporating the image with an image map
	if options[:layout].nil? or !options[:layout]
 html_file.write("<HEAD><TITLE>JFreeChart Image Map</TITLE></HEAD>\n")
 html_file.write("<BODY>\n");
	end
	html_file.write(ChartUtilities.getImageMap("chart", info));

	if image_file
 FileUtils.mv(temp_image_file, image_file)
 html_file.write("<IMG SRC=\"#{image_file.to_s}\" " +
	  "WIDTH=\"#{width}\" HEIGHT=\"#{height}\" BORDER=\"0\" USEMAP=\"#chart\">\n")
	else
 image_data = Base64.encode64(temp_image_file.open("r").read)
 html_file.write("<IMG SRC=\"data:image/png;base64,#{image_data}\" " +
	  "WIDTH=\"#{width}\" HEIGHT=\"#{height}\" BORDER=\"0\" USEMAP=\"#chart\">\n")	  
	end
	if options[:layout].nil? or !options[:layout]
 html_file.write("</BODY>\n");
 html_file.write("</HTML>\n");
	end
	html_file.string
    else
	raise "Cannot render to #{mime_type.inspect}"
    end   
  }
end