如何在Highcharts中将导出按钮更改为自定义图标

时间:2019-10-23 19:42:32

标签: jquery html highcharts

我正在使用Highcharts,在这里我需要将右侧的导出按钮更改为下载图标/图像。另外还有图例文字,例如安装,将颜色制造为与特定系列的颜色相同,我指的是与图例文字之前的图标相同的颜色。这是下面的代码

html

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container"></div>

script.js

Highcharts.chart('container', {

    title: {
        text: 'Solar Employment Growth by Sector, 2010-2016'
    },

    subtitle: {
        text: 'Source: thesolarfoundation.com'
    },

    yAxis: {
        title: {
            text: 'Number of Employees'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: 2010
        }
    },

    series: [{
        name: 'Installation',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }, {
        name: 'Manufacturing',
        data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
    }, {
        name: 'Sales & Distribution',
        data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
    }, {
        name: 'Project Development',
        data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
    }, {
        name: 'Other',
        data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});

2 个答案:

答案 0 :(得分:0)

您需要在图例中使用labelFormatter来更改标签文本的颜色:

 labelFormatter: function() {
  return '<span style="color: ' + this.color + '">' + this.name + '</span>';
}

工作中的小提琴在这里:https://jsfiddle.net/narkhedetusshar/61mqao9w/15/

答案 1 :(得分:0)

您可以通过编辑contextButton属性来更改导出按钮:

exporting: {
    buttons: {
        contextButton: {
            symbol: 'circle',
            symbolStrokeWidth: 1,
            symbolFill: '#a4edba',
            symbolStroke: '#330033'
        }
    }
}

要更改图例项的文本颜色,请使用labelFormatter函数:

legend: {
    labelFormatter: function() {
        return '<span style="color: ' + this.color + '">' + this.name + '</span>';
    }
}

实时演示: https://jsfiddle.net/BlackLabel/12pvu9Lj/

API参考:

https://api.highcharts.com/highcharts/exporting.buttons.contextButton.symbol

https://api.highcharts.com/highcharts/legend.labelFormatter