<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 17.3 實例代碼 ### 17.3.1 JFreeChart 和Batik JFreeChart和Batik兼容性非常好,因為: + 因為JFreeChart畫的所有圖表的輸出都是使用的Java的Graphics2D; + Batik具體實現了Graphics2D產生SVG輸出的功能(SVGGraphics2D)。 在本章節,使用一個簡單的實例說明使用JFreeChart和Batik實現SVG的輸出。關于該實例的詳細技術詳見下面鏈接: [http://xml.apache.org/batik/svggen.html](http://xml.apache.org/batik/svggen.html) ### 17.3.2 開始 首先,我們需要下載Batik并依照網站的指導進行安裝。 確保下章節的例子能夠正常運行,需要將下面的jar包加到我們的classpath: | 文件 | 描述 | | --- | --- | | jcommon-1.0.9.jar | JFreeChart的通用類包。 | | jfreechart-1.0.6.jar | JFreeChart的類包 | | batik-awt-util.jar | Batik實時運行文件 | | batik-dom.jar | Batik實時運行文件 | | batik-svggen.jar | Batik實時運行文件 | | batik-util.jar | Batik實時運行文件 | ### 17.3.3 實例應用 在我們的開發環境中創建一個工程,并且將上節列出的jar包添加到工程路徑上,并輸入下面代碼: ``` package demo; import java.awt.geom.Rectangle2D; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import org.apache.batik.dom.GenericDOMImplementation; import org.apache.batik.svggen.SVGGraphics2D; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; /** * A demonstration showing the export of a chart to SVG format. */ public class SVGExportDemo { /** * Starting point for the demo. * * @param args * ignored. */ public static void main(String[] args) throws IOException { // create a dataset... DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Category 1", new Double(43.2)); data.setValue("Category 2", new Double(27.9)); data.setValue("Category 3", new Double(79.5)); // create a chart JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart", data, true, false, false); // THE FOLLOWING CODE BASED ON THE EXAMPLE IN THE BATIK DOCUMENTATION... // Get a DOMImplementation DOMImplementation domImpl = GenericDOMImplementation .getDOMImplementation(); // Create an instance of org.w3c.dom.Document Document document = domImpl.createDocument(null, "svg", null); // Create an instance of the SVG Generator SVGGraphics2D svgGenerator = new SVGGraphics2D(document); // set the precision to avoid a null pointer exception in Batik 1.5 svgGenerator.getGeneratorContext().setPrecision(6); // Ask the chart to render into the SVG Graphics2D implementation chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null); // Finally, stream out SVG to a file using UTF-8 character to // byte encoding boolean useCSS = true; Writer out = new OutputStreamWriter(new FileOutputStream(new File( "test.svg")), "UTF-8"); svgGenerator.stream(out, useCSS); } } ``` ### 17.3.4 瀏覽SVG圖 Batik類庫內包含了一個”Squiggle”的小應用,我們可以使用該工具瀏覽SVG文件。我們可以使用下面命令打開: ``` java -jar batik-squiggle.jar ``` 下圖截屏顯示了上述代碼創建的一個餅圖的界面。使用應用瀏覽器工具,將圖表在瀏覽器中進行了45度旋轉。 ![](img/jfc111390.png) 如圖17.1 SVG截圖
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看