Java jfreechart将多个数据集转换为svg图像
我正在使用JFreeChart从csv文件填充图形,我已设法从该文件创建多个数据集并将数据绘制成图形 SVG图像正在被重新写入到“file.SVG”中,因此看起来没有什么好看的。问题是,我如何从多个数据集中创建单个SVG图像,如果我知道如何获取每个图表,将其有序地绘制,并将所有图表绘制到SVG文件中Java jfreechart将多个数据集转换为svg图像,java,svg,jfreechart,Java,Svg,Jfreechart,我正在使用JFreeChart从csv文件填充图形,我已设法从该文件创建多个数据集并将数据绘制成图形 SVG图像正在被重新写入到“file.SVG”中,因此看起来没有什么好看的。问题是,我如何从多个数据集中创建单个SVG图像,如果我知道如何获取每个图表,将其有序地绘制,并将所有图表绘制到SVG文件中 包装自由图; 导入java.util.*; 导入java.text.*; 导入java.io.*; 导入java.awt.*; 导入java.util.StringTokenizer; 导入ja
包装自由图;
导入java.util.*;
导入java.text.*;
导入java.io.*;
导入java.awt.*;
导入java.util.StringTokenizer;
导入javax.swing.*;
导入org.apache.batik.dom.GenericDOMImplementation;
导入org.apache.batik.svggen.SVGGraphics2D;
导入org.jfree.chart.*;
导入org.jfree.chart.axis.*;
导入org.jfree.chart.plot.*;
导入org.jfree.chart.renderer.xy.*;
导入org.jfree.data.time.*;
导入org.jfree.ui.*;
导入org.w3c.dom.dom实现;
导入org.w3c.dom.Document;
导入java.awt.Rectangle;
导入java.awt.geom.Rectangle2D;
公共类股票历史图表扩展JPanel
{
私有静态最终长serialVersionUID=1L;
//保存数据
公共TimeSeriesCollection数据集=新TimeSeriesCollection();
public timeseriescolection datasetPhysical=new timeseriescolection();
公共TimeSeriesCollection数据集=新TimeSeriesCollection();
public timeseriescolection datasetMM=新timeseriescolection();
public timeseriescolection datasetIF=new timeseriescolection();
public timeseriescolection datasetWP=new timeseriescolection();
//创建图表
@抑制警告(“未使用”)
私人海图;
//创建一个可以显示图表的面板
@抑制警告(“未使用”)
私人查特小组;
私有字符串符号;
私人字符串当前月;
@SuppressWarnings({“弃用”、“资源”、“未使用的”})
公共股票历史图表(字符串文件名)
{
尝试
{
//获取股票符号
this.stockSymbol=filename.substring(0,filename.indexOf('.');
//创建时间序列
TimeSeries PVC=新的TimeSeries(“物理计数”,Day.class);
//TimeSeries PV=新的TimeSeries(“物理”,Day.class);
TimeSeries STKC=新的TimeSeries(“S Count”,Day.class);
//TimeSeries STKTP=新的TimeSeries(“S”,Day.class);
TimeSeries MMTPC=新的TimeSeries(“MM计数”,Day.class);
//TimeSeries MMTP=新的TimeSeries(“MM”,Day.class);
TimeSeries IFSC=新的TimeSeries(“如果计数”,Day.class);
//TimeSeries IFSTP=新的TimeSeries(“IF”,Day.class);
TimeSeries WPC=新的TimeSeries(“WP计数”,Day.class);
//TimeSeries WPTP=新的TimeSeries(“WP”,Day.class);
BufferedReader br=新的BufferedReader(新文件读取器(文件名));
字符串键=br.readLine();
String line=br.readLine();
while(行!=null&&
!line.startsWith(“我解决了我面临的这个问题(无法创建包含所有图表的SVG文件),方法是删除exportChartAsSVG()并从主函数调用SVG生成器,如下所示
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// Ask the shc to render into the SVG Graphics2D implementation.
shc.paint(svgGenerator);
// Create a SVG file to populate our Frame
File svgFile = new File ("svgfile.svg");
FileOutputStream fos = new FileOutputStream(svgFile);
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
boolean useCSS = true; // we want to use CSS style attributes
Writer out = new OutputStreamWriter(fos, "UTF-8");
svgGenerator.stream(out, useCSS);
out.flush();
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// Ask the shc to render into the SVG Graphics2D implementation.
shc.paint(svgGenerator);
// Create a SVG file to populate our Frame
File svgFile = new File ("svgfile.svg");
FileOutputStream fos = new FileOutputStream(svgFile);
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
boolean useCSS = true; // we want to use CSS style attributes
Writer out = new OutputStreamWriter(fos, "UTF-8");
svgGenerator.stream(out, useCSS);
out.flush();