Echarts实战案例代码(23):富文本实现坐标轴文字和图片排版的解决方案

简介: Echarts实战案例代码(23):富文本实现坐标轴文字和图片排版的解决方案


图片对象路径

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


X轴富文本

    xAxis: {
        type: 'category',
        data: ['Sunny', 'Cloudy', 'Showers'],
        axisLabel: {
            formatter: function (value) {
                console.log(value);
                return '{' + value + '| }\n{value|' + value + '}';
            },
            margin: 20,
            rich: {
                value: {
                    lineHeight: 30,
                    align: 'center'
                },
                Sunny: {
                    height: 30,
                    align: 'center',
                    backgroundColor: {
                        image: weatherIcons.Sunny
                    }
                },
                Cloudy: {
                    height: 30,
                    align: 'center',
                    backgroundColor: {
                        image: weatherIcons.Cloudy
                    }
                },
                Showers: {
                    height: 30,
                    align: 'center',
                    backgroundColor: {
                        image: weatherIcons.Showers
                    }
                }
            }
        }
    },


代码解析

  1. 1.axisLabel使用formatter回调函数,将data中的value转为变量;
  2. 2.rich富文本样式表中,对应axisLabel的value,进而实现图片和文字的排版;


Done!

相关文章
|
3月前
|
前端开发 JavaScript BI
Django教程第5章 | Web开发实战-数据统计图表(echarts、highchart)
使用echarts和highcharts图表库实现折线图、柱状图、饼图和数据集图
64 2
|
6月前
ECharts 柱状图横轴(X轴)文字内容显示不全
ECharts 柱状图横轴(X轴)文字内容显示不全
128 0
|
4天前
|
前端开发 JavaScript 定位技术
Docusaurus框架——react+antd+echarts自定义mdx生成图表代码解释文档
Docusaurus框架——react+antd+echarts自定义mdx生成图表代码解释文档
20 0
|
2月前
|
前端开发 JavaScript Apache
web前端-Echarts-5.3安装配置和案例
web前端-Echarts-5.3安装配置和案例
|
4月前
|
数据可视化
Echarts5.3.2可视化案例-时间轴动态柱形图
Echarts5.3.2可视化案例-时间轴动态柱形图
|
9月前
echarts 图表解决X轴加滚动条之后文字过多不显示问题
echarts 图表解决X轴加滚动条之后文字过多不显示问题
68 0
|
5月前
|
JavaScript
引入echarts时报错 “TypeError: Cannot read properties of undefined (reading ‘init‘)“的解决方案
引入echarts时报错 “TypeError: Cannot read properties of undefined (reading ‘init‘)“的解决方案
182 0
引入echarts时报错 “TypeError: Cannot read properties of undefined (reading ‘init‘)“的解决方案
|
5月前
Echarts柱状图x轴刻度间隔显示不全/x轴文字倾斜
Echarts柱状图x轴刻度间隔显示不全/x轴文字倾斜
62 0
|
6月前
|
JSON 数据格式
ECharts加载json数据解决方案
ECharts加载json数据解决方案
38 0
|
6月前
echarts中矢量图片路径设置
echarts中矢量图片路径设置