Search code examples
javascriptchartshighchartspie-chart

Change Highchart's pie chart .xls file category column name


I am using Pie Chart of Highcharts and I want to download the generated .xls file with custom columns names. By default the columns are name 'Category' and 'You series name' (in my case it's 'Percentage (%)'. Mainly I want to change the Category name, but couldn't find a way.

this is the javascript code of the chart:

janChart = Highcharts.chart('January', {
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false,
                type: 'pie'
            },
            title: {
                text: 'Applications BW Usage in January, 2019'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    size:'80%',
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                        style: {
                            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                        },
                        connectorColor: 'silver'
                    }
                }
            },
            series: [{
                name: 'Percentage (%)',
                data: [
                ]
            }]
        });

.xls file image

the chart


Solution

  • Use columnHeaderFormatter function:

    exporting: {
        csv: {
            columnHeaderFormatter: function(item, key) {
                if (!key) {
                    return 'custom title'
                }
                return false
            }
        }
    },
    

    Live demo: https://jsfiddle.net/BlackLabel/n6oLmyw3/

    API Reference: https://api.highcharts.com/highcharts/exporting.csv.columnHeaderFormatter