java - 导出的 SVG 溢出边界
问题描述
我正在使用 vaadin-charts:3.2.0 可视化一些数据,并且我正在尝试从图表中导出 SVG。我得到了一些结果,但并不令人满意。我只能共享屏幕主机而不是 SVG 本身。我还必须对标签进行像素化以掩盖私人数据。
在屏幕上看到的原始 vaadin 图表:
导出的 SVG:
一个问题是标签溢出了 svg 边界。并且图表图纸也超出了边界,使其看起来像是一张不完整的图纸。知道这个结构有什么问题吗?
public class SvgStreamResource extends StreamResource {
public SvgStreamResource(String svgText, String filename) {
super(new StreamSource() {
@Override
public InputStream getStream() {
InputStream s = new BufferedInputStream( new ReaderInputStream(new StringReader(svgText)));
return s;
}
}, filename + ".svg");
}
@Override
public String getMIMEType() {
return "image/svg+xml";
}
}
在一个组件内:
Button exportButton = createExportButton("SVG", createSVGStreamSource(conf));
private SvgStreamResource createSVGStreamSource(Configuration conf) {
String svg = SVGGenerator.getInstance().generate(conf);
return new SvgStreamResource(svg, fileBaseName);
}
private Button createExportButton(String caption, SvgStreamResource svgStreamResource) {
Button b = new Button(caption);
FileDownloader downloader = new FileDownloader(svgStreamResource);
downloader.extend(b);
return b;
}
解决方案
推荐阅读
- android - 在清理后安装应用程序时,被删除的 Android 本地文件重新出现
- html - 如何对 form_tag 路径上传递的参数进行排序?
- php - 为什么 laravel 验证不显示错误
- node.js - 使用 express 作为提要时如何打包电子应用程序?
- oracle - DBMS_SCHEDULER 链作业未发送失败的电子邮件
- sql - 从 datetime 更改为 datetime2 会导致错误吗?
- javascript - 如何将 Mapbox Geocoder 结果地点/国家/地区文本名称转换为 JavaScript 函数?
- regex - 如何使用正则表达式(谷歌风格)提取 3 个子字符串?
- reactjs - 在查询完成之前阻止渲染?
- r - R中是否有一个函数可以删除数千行给定的特定内容?