Echarts 条形图富文本图标

问题描述 投票:0回答:1

我正在尝试让我的图表有图标。

所以我按照文档并提出了以下内容:

var weatherIcons = {
    'Sunny': './data/asset/img/weather/sunny_128.png',
    'Cloudy': './data/asset/img/weather/cloudy_128.png',
    'Showers': './data/asset/img/weather/showers_128.png'
};

var seriesLabel = {
    normal: {
        show: true,
        textBorderColor: '#333',
        textBorderWidth: 2
    }
}

option = {
    title: {
        text: 'Wheater Statistics'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    legend: {
        data: ['City Alpha', 'City Beta', 'City Gamma']
    },
    toolbox: {
        show: true,
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        name: 'Days',
        data: ['Cloudy', 'Sunny', 'Showers'],

        formatter: function (value) {
            return '{' + value + '| }\n{value|' + value + '}';
        },
        axisLabel: {
            margin: 20,
            rich: {
                value: {
                    lineHeight: 30,
                    align: 'center'
                },
                Sunny: {
                    height: 20,
                    align: 'center',
                    backgroundColor: {
                        image: weatherIcons.Sunny
                    }
                },
                Cloudy: {
                    height: 20,
                    align: 'center',
                    backgroundColor: {
                        image: weatherIcons.Cloudy
                    }
                },
                Showers: {
                    height: 20,
                    align: 'center',
                    backgroundColor: {
                        image: weatherIcons.Showers
                    }
                }
            
            }
        
        }
    },
    yAxis: {
    },
    series: [
        {
            name: 'City Alpha',
            type: 'bar',
            data: [165, 170, 30],
            
        },
        {
            name: 'City Beta',
            type: 'bar',
            label: seriesLabel,
            data: [150, 105, 110]
        },
        {
            name: 'City Gamma',
            type: 'bar',
            label: seriesLabel,
            data: [220, 82, 63]
        }
    ]
};

您可以通过以下链接进行测试:链接到 Echarts 并粘贴代码。

如何让图表显示图标?

javascript html echarts
1个回答
2
投票

formatter的功能

错误的地方

formatter
应位于
axisLabel

示例:

xAxis: {
   // ....
   axisLabel: {
      formatter: function (value) {
         return '{' + value + '| }\n{value|' + value + '}';
      },
      // ....
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.