HighCharts - 导出图表时忽略setTitle() [英] HighCharts - setTitle() ignored when exporting chart

查看:182
本文介绍了HighCharts - 导出图表时忽略setTitle()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在文档加载上创建HighCharts图表,然后当用户更改某些设置时,其他代码将更新图表。我使用 chart.setTitle()命令更改标题,屏幕图表更新正常。



但是当图表导出为任何图像类型时,图表默认返回到图表标题的空图表的标题。动态标题不会导出。



查看我的 JSFiddle 这里。点击图表右上角的导出图标,然后选择下载PNG图像或任何其他选项。下载的图像将显示图表标题,​​而不是代码指定的标题和字幕。



任何人都有任何想法我在这里做错什么?非常感谢您的帮助!

  $(function(){
var chart;
$(文件).ready(function(){
chart = new Highcharts.Chart({
chart:{
renderTo:'ChartContainer',
type:spline
},

系列:[{
数据:[29.9,71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4]}],
$)

chart.setTitle({
text:testing
},{
text:这是一个测试
});

});
});


解决方案

基于bug#48中的解决方案的示例: p>

http://jsfiddle.net/cjc343/LHSey / 1 /



Bug#48:



https://github.com/highslide-software/highcharts.com/issues/48



论坛讨论问题:



http://highslide.com/forum/viewtopic.php?f=9&t=8951



简而言之,导出时不会对图表选项进行更改,除非您明确更改了最初用于呈现图表的默认值。


My code creates a HighCharts chart on the document load, then other code will update the chart when the user changes certain settings. I change the title with the chart.setTitle() command and the on-screen chart updates just fine.

But when the chart is exported as any image type, the chart defaults back to the title of an empty chart which is "Chart Title". The dynamic title doesn't get exported.

See my JSFiddle here. Click the little "export" icon at the top-right of the chart and choose "Download PNG Image" or any other option. The downloaded image will show "Chart Title" instead of the code-specified Title and Subtitle.

Anyone have any ideas what I'm doing wrong here? Thanks so much for your help!

$(function() {
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'ChartContainer',
                type: "spline"
            },

            series: [{
                data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]}],
        });

        chart.setTitle({
            text: "Testing"
        }, {
            text: "This is a test"
        });

    });
});

解决方案

Example based on solutions in bug #48:

http://jsfiddle.net/cjc343/LHSey/1/

Bug #48:

https://github.com/highslide-software/highcharts.com/issues/48

Forum discussion of issue:

http://highslide.com/forum/viewtopic.php?f=9&t=8951

In short, changes to the chart options are not applied when exporting unless you explicitly change the defaults that were originally used to render the chart.

这篇关于HighCharts - 导出图表时忽略setTitle()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆