【问题标题】:How to change export button to custom icon in highcharts如何将导出按钮更改为highcharts中的自定义图标
【发布时间】:2019-10-24 22:11:30
【问题描述】:

我正在使用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'
                }
            }
        }]
    }

});

【问题讨论】:

    标签: jquery html highcharts


    【解决方案1】:

    您可以通过编辑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

    【讨论】:

    • 感谢您的回答,在 Angular 7 中出现编译错误,“颜色”属性不会连续退出
    • 嗨@UIAPPDEVELOPER,您可以尝试参考一些外部颜色。示例:jsfiddle.net/BlackLabel/f0yw3bu4
    【解决方案2】:

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

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

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

    【讨论】:

    • 感谢您的回答,在 Angular 7 中出现编译错误,“颜色”属性不会连续退出
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2014-07-02
    • 1970-01-01
    相关资源
    最近更新 更多