Highcharts在导出时添加图例 [英] Highcharts add legend on export

查看:127
本文介绍了Highcharts在导出时添加图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在将图表导出为PNG时在饼图上添加图例。
这是我的代码:

I'm trying to add a legend on a pie when exporting the chart as PNG. Here is my code :

var chart_23_106;
$(document).ready(function () {
chart_23_106 = new Highcharts.Chart({
    chart: { type: 'pie', renderTo: 'container_23_106', plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false },
    title: { text: 'NRJ' },
    tooltip: { pointFormat: '{series.name}: <b>{point.percentage}%</b>', percentageDecimals: 1 },
    plotOptions: {
        pie: { borderWidth: 0, shadow: false, allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: false } }
    },
    colors: ['#9F9F9F','#BE6EBE','#FFA74F','#B7B7D0','#CBE22A','#00C8C8'],
    credits: { enabled: false, text: "Source: Air Normand", href: "" },
    exporting:{ buttons: {
            printButton: {enabled:false},
            exportButton: {menuItems:null,onclick:function(){this.exportChart(null, 
                                        { chart: {reflow: false, width: 400}, 
                                          title: {text: "Répartition de la Consommation"}, 
                                          subtitle: {text: "Haute-Normandie"}, 
                                          plotOptions: {pie: {dataLabels: {enabled: true}, showInLegend: true}}, 
                                          credits: {enabled: true} }
                                    );}}
    }},
    lang: {exportButtonTitle: "Export image au format PNG"},
    series: [{
        type: 'pie',
        name: 'Proportion',
        data: [
        ['Activite 1',   684.6],
        ['Activite 2',   564.7],
        ['Activite 3',   244.4],
        ['Activite 4',   42.8],
        ]
    }]
});
});

在函数exportChart中,除了plotOptions之外的所有函数都会产生正确的效果。在PNG文件中,标题被更改,添加了字幕和点数,但dataLabels和图例不显示...

任何人都知道为什么?

任何人都可以帮助我 ?
谢谢

In the function exportChart, all but the plotOptions gives the right effect. In the PNG file, the title is changed, subtitle and credits are added, but the dataLabels and the legend don't appear...
Anyone knowing why ?
Could anyone help me ? Thanks

推荐答案

是的,可以通过禁用图表中的图例和导出参数( http://api.highcharts.com/highcharts#exporting.chartOptions )将此选项设置为活动状态。

Yes it is possible by disabling legend in chart and in exporting parameters (http://api.highcharts.com/highcharts#exporting.chartOptions) set this option as active.

工作示例: http://jsfiddle.net/xvQNA/

var chart;
$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2010'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage}%</b>',
            percentageDecimals: 1
        },
        legend:{
            enabled:false
        },
        exporting:{
            chartOptions:{
                legend:{
                    enabled:true
                }
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            showInLegend:true,
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]
    });
});

这篇关于Highcharts在导出时添加图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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