Save a chart object as a pdf document.
Arguments:
chart
filename
Options:
:width (default 500)
:height (defualt 400)
Examples:
(use '(incanter core charts pdf))
(save-pdf (function-plot sin -4 4) "./pdf-chart.pdf")
(defn save-pdf
" Save a chart object as a pdf document.
Arguments:
chart
filename
Options:
:width (default 500)
:height (defualt 400)
Examples:
(use '(incanter core charts pdf))
(save-pdf (function-plot sin -4 4) \"./pdf-chart.pdf\")
"
([chart filename & options]
(let [opts (when options (apply assoc {} options))
width (or (:width opts) 500)
height (or (:height opts) 400)
pagesize (Rectangle. width height)
document (Document. pagesize 50 50 50 50)
out (BufferedOutputStream. (FileOutputStream. filename))
writer (PdfWriter/getInstance document out)
_ (.open document)
cb (.getDirectContent writer)
tp (.createTemplate cb width height)
mapper (DefaultFontMapper.)
g2 (.createGraphics tp width height mapper)
r2D (new java.awt.geom.Rectangle2D$Double 0 0 width height)]
(do
(.draw chart g2 r2D)
(.dispose g2)
(.addTemplate cb tp 0 0)
(.close document)
(.close out)))))
Comments top
No comments for save-pdf. Log in to add a comment.