comparison gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java @ 639:a94ed2755480

Implemented SVG export for histograms. gnv-artifacts/trunk@724 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Mar 2010 14:48:32 +0000
parents 65f09139e9b3
children e5f1e868ee3e
comparison
equal deleted inserted replaced
638:c580666a843f 639:a94ed2755480
87 chart.draw(g, new Rectangle2D.Double(0.0D, i*height, width, height)); 87 chart.draw(g, new Rectangle2D.Double(0.0D, i*height, width, height));
88 } 88 }
89 g.finalize(); 89 g.finalize();
90 90
91 ImageIO.write(image, format, out); 91 ImageIO.write(image, format, out);
92 }
93
94
95 public static void exportHistogramsAsSVG(
96 OutputStream out,
97 Chart[] histograms,
98 String encoding,
99 int width,
100 int height
101 ) {
102 log.info("export histograms as svg");
103
104 if (encoding == null)
105 encoding = DEFAULT_ENCODING;
106
107 org.w3c.dom.Document document = XMLUtils.newDocument();
108 SVGGraphics2D graphics = new SVGGraphics2D(document);
109
110 int size = histograms.length;
111 for (int i = 0; i < size; i++) {
112 JFreeChart chart = histograms[i].generateChart();
113 chart.draw(graphics, new Rectangle2D.Double(
114 0.0D, i*height,width,height));
115 }
116 graphics.finalize();
117
118 try {
119 graphics.stream(new OutputStreamWriter(out, encoding));
120 }
121 catch (SVGGraphics2DIOException svge) {
122 log.error("Error while writing svg export to output stream.", svge);
123 }
124 catch (UnsupportedEncodingException uee) {
125 log.error("Unsupported encoding: " + encoding, uee);
126 }
92 } 127 }
93 128
94 129
95 public static void exportSVG( 130 public static void exportSVG(
96 OutputStream out, 131 OutputStream out,

http://dive4elements.wald.intevation.org