繁体   English   中英

条形图上的Echarts富文本图标

[英]Echarts rich text icons on bar chart

我正在尝试使我的图表带有图标。

所以我遵循了文档,并提出了以下内容:

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并粘贴代码。

但是,我可以得到图表来显示图标。

有人可以帮我吗?

您的formatter功能位置错误

formatter应位于axisLabel内部

例:

xAxis: {
   // ....
   axisLabel: {
      formatter: function (value) {
         return '{' + value + '| }\n{value|' + value + '}';
      },
      // ....
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM