6

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

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和图例......
有人知道为什么吗?
谁能帮助我?谢谢

4

3 回答 3

11

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

工作示例: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]
            ]
        }]
    });
});
于 2013-02-21T09:00:46.197 回答
1

对我来说,当我在导出选项中禁用导航时它起作用了:

  exporting: {
    chartOptions: {
      legend: {
        navigation: {
          enabled: false
        }
      }
    }
  },
于 2018-05-23T08:48:28.820 回答
0

你只需要添加 enable: truedataLabels:

    plotOptions: {
        series: {
            dataLabels: {
                enabled: true,
            }
        }
    }
于 2015-04-14T22:20:52.430 回答