Vue echarts x轴或y轴文本字体颜色改变、设置x轴间隔显示 interval: 1

本文详细介绍了如何使用Echarts配置项改变x轴和y轴的文本字体颜色。通过设置axisLabel的textStyle属性,可以全局修改颜色,或者使用function动态设置不同索引位置的标签颜色。示例代码中展示了前几个、中间部分和后面几个标签分别设置不同颜色的方法,以及x轴间隔显示的配置。
摘要由CSDN通过智能技术生成

echarts x轴或y轴文本字体颜色改变 - 童心小城 - 博客园

1:x轴文本字体颜色改变

xAxis : [
                    {
                        type : 'category',
                        data : ['<30','30-','40-','50-','60-','>=70'],
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    }
                ]

2.y轴文本字体颜色改变

yAxis : [
                    {
                        type : 'value',
                        name : '%',
                        axisLabel : {
                            formatter: '{value}',
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    }
        ]

3.修改前面几个颜色后面几个颜色

xAxis: [
              {
                type: "category",
                data: xdata,["广州","深圳",],
                axisLabel: {
                  color: "#D3E4FF",
                  fontFamily: "PingFangSC-Medium",
                  fontSize: 14,
                  clickable: true,
                  textStyle: {
                    color: function (params, index) {
                      let colorValue;
                      if (index <= 5) {
                        colorValue = "#32CC7F";//前面6个
                      } else if (index > 5 && index <= 14) {
                        colorValue = "#FFA800";//中间9个
                      } else if (index > 8) {
                        colorValue = "#F81D22";//后面的几个
                      }
                      return colorValue;
                    },
                  },
                },
              },
            ],

设置x轴间隔显示 interval: 1

var myChart12 = echarts.init(document.getElementById('chart12'));
        option12 = {
            color: ['#63AFF9'],
            xAxis: {
                type: 'category',
                data:["示范区", "禹王台区", "龙亭区"],
                axisLabel: {
                    interval: 1  //0:表示全部显示不间隔;auto:表示自动根据刻度个数和宽度自动设置间隔个数
                }
            },
            yAxis: {
                type: 'value',
                name: '家'
            },
            series: [{undefined
                data: [80, 32, 90, 34, 129, 133, 130, 200, 16, 150, 188, 178, 156],
                type: 'line'
            }]
        };
        myChart12.setOption(option12)

要在 Vue2 中使用 ECharts 实现 x y 气泡图,你需要先安装 ECharts。 可以通过 npm 或 yarn 安装 ECharts: ```bash npm install echarts --save # 或者 yarn add echarts ``` 安装完成后,在 Vue 组件中引入 ECharts: ```javascript import echarts from 'echarts' ``` 然后在组件的 mounted 钩子函数中初始化 ECharts 实例: ```javascript mounted () { // 初始化 ECharts 实例 const chart = echarts.init(this.$refs.chart) // 具体的 ECharts 配置 const option = { // 配置项 } // 使用刚指定的配置项和数据显示图表 chart.setOption(option) } ``` 对于气泡图,可以使用 scatter 和 visualMap 组件实现。以下是一个简单的示例: ```javascript mounted () { // 初始化 ECharts 实例 const chart = echarts.init(this.$refs.chart) // ECharts 配置 const option = { xAxis: { type: 'value', scale: true }, yAxis: { type: 'value', scale: true }, visualMap: { min: 0, max: 100, dimension: 2, calculable: true, orient: 'horizontal', left: 'center', bottom: '15%' }, series: [{ type: 'scatter', data: [ [10.0, 8.04, 10], [8.0, 6.95, 30], [13.0, 7.58, 20], [9.0, 8.81, 50], [11.0, 8.33, 80], [14.0, 9.96, 40], [6.0, 7.24, 70], [4.0, 4.26, 90], [12.0, 10.84, 60], [7.0, 4.82, 100], [5.0, 5.68, 10] ], symbolSize: function (data) { return Math.sqrt(data[2]) }, label: { emphasis: { show: true, formatter: function (param) { return param.data[2] }, position: 'top' } }, itemStyle: { normal: { shadowBlur: 10, shadowColor: 'rgba(120, 36, 50, 0.5)', shadowOffsetY: 5, color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{ offset: 0, color: 'rgb(251, 118, 123)' }, { offset: 1, color: 'rgb(204, 46, 72)' }]) } } }] } // 使用刚指定的配置项和数据显示图表 chart.setOption(option) } ``` 在模板中添加一个 div 占位符,并设置 ref 属性为 chart: ```html <template> <div ref="chart" style="width: 100%; height: 400px;"></div> </template> ``` 这样就可以在 Vue2 中使用 ECharts 实现 x y 气泡图了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值