简体   繁体   English

将Highcharts导出到jsPDF-CANVG错误

[英]Export Highcharts to jsPDF - canvg error

I'm looking for a solution about highcharts export to PDF with jsPDF. 我正在寻找有关使用jsPDF将海图导出到PDF的解决方案。 I used this solution to export my graph as image to my pdf -> Export Highcharts to PDF (using javascript and local server - no internet connection) 我使用此解决方案将图形作为图像导出到pdf- > 将Highcharts导出为PDF(使用javascript和本地服务器-没有Internet连接)

It's working fine, but for some graph i could not generate the image because of this error : 它工作正常,但是对于某些图形,由于此错误,我无法生成图像:

Uncaught TypeError: undefined is not a function -- canvg.js:2000
svg.Element.text.getAnchorDelta -- canvg.js:2010
svg.Element.text.renderChild -- canvg.js:1989
svg.Element.text.renderChildren -- canvg.js:679
svg.Element.ElementBase.render -- canvg.js:698
svg.Element.ElementBase.renderChildren -- canvg.js:679
svg.Element.ElementBase.render -- canvg.js:698
svg.Element.ElementBase.renderChildren -- canvg.js:679
svg.Element.ElementBase.render -- canvg.js:2723
svg.loadXmlDoc.draw -- canvg.js:2733
svg.loadXmlDoc -- canvg.js:2646
svg.loadXml -- canvg.js:62
canvg -- indicateurs.js:3237
$.bind.H.Chart.createCanvas -- indicateurs.js:3171
(anonymous function) -- jquery-1.10.2.min.js:4
x.extend.each -- indicateurs.js:3164
_indicateurs.hightcharts.graph_to_pdf -- indicateurs.js:3262
(anonymous function) -- jquery-1.10.2.min.js:5
x.event.dispatch -- jquery-1.10.2.min.js:5
x.event.add.v.handle

Following, the canvas method throwing the error (canvg.js) : 接下来,canvas方法抛出错误(canvg.js):

        this.getAnchorDelta = function (ctx, parent, startI) {
            var textAnchor = this.style('text-anchor').valueOrDefault('start');
            if (textAnchor != 'start') {
                var width = 0;
                for (var i=startI; i<parent.children.length; i++) {
                    var child = parent.children[i];
                    if (i > startI && child.attribute('x').hasValue()) break; // new group
                    width += child.measureTextRecursive(ctx);       // ######## PROBLEM LOCATED ON THIS LINE
                }
                return -1 * (textAnchor == 'end' ? width : width / 2.0);
            }
            return 0;
        }

Any first ideas about what could be make this error ? 关于可能导致此错误的任何第一个想法?

Use this bower package: 使用此凉亭包:

"canvg-gabelerner": "*"

And make sure you include these 3 dependencies: 并确保您包括以下3个依赖项:

<script src="bower_components/canvg-gabelerner/rgbcolor.js"></script>
<script src="bower_components/canvg-gabelerner/StackBlur.js"></script>
<script src="bower_components/canvg-gabelerner/canvg.js"></script>

The canvg bower package is old. canvg凉亭包装很旧。 It was created because original repo was stored on Google code service (now dead). 之所以创建它,是因为原始存储库已存储在Google代码服务中(现已失效)。

I hope it helps! 希望对您有所帮助! :) :)

It is one of the common issues in HighCharts. 这是HighCharts中的常见问题之一。 This is due to the wrapped text that is found within the <title></title> tag. 这是由于在<title></title>标记中找到了换行符。 This usually occurs if your axis labels are too long and they are wrapped to multiple lines. 如果您的轴标签太长并且被包裹成多行,通常会发生这种情况。 The simple way to resolve this error is to remove all the title elements before exporting to PDF. 解决此错误的简单方法是在导出为PDF之前删除所有title元素。 This doesn't affect any part of your chart. 这不会影响图表的任何部分。

To remove the title element within your chart container, use JQuery 要删除图表容器中的title元素,请使用JQuery

("#chart_container_id title").remove();

Insert this line at the beginning of the exporting module. 将此行插入导出模块的开头。 Now try to export and this will work fine. 现在尝试导出,它将正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM