微信小程序echarts雷达图tooltip的显示

微信小程序雷达图tooltip的显示

我们要显示这样的效果:
在这里插入图片描述
看着十分简单,在echarts实例上用的十分愉快,可一放到小程序上他就变成了“漂亮”的一排,本该换行的地方全变成了这样:

在这里插入图片描述
让人好不烦躁。那怎样解决了?我解决的方法如下:

主要代码:

 tooltip: {
      confine: true,
      enterable: true, //鼠标是否可以移动到tooltip区域内
      formatter: function (param) {
        return param.name + '\n' +
          indicators[0].name + ':' + param.value[0] + '\n' +
          indicators[1].name + ':' + param.value[1] + '\n' +
          indicators[2].name + ':' + param.value[2] + '\n' +
          indicators[3].name + ':' + param.value[3] + '\n' +
          indicators[4].name + ':' + param.value[4] + '\n' +
          indicators[5].name + ':' + param.value[5] + '\n'
      }
    },

全部代码:

function getOption() {
  var colors = ['rgba(252,157,154,1)', 'rgba(28,120,135,1)', 'rgba(255,252,153,1)']
  var indicators = [{
      name: '语文成绩',
      max: 150
    },
    {
      name: '数学成绩',
      max: 150
    },
    {
      name: '外语成绩',
      max: 150
    },
    {
      name: '化学成绩',
      max: 100
    },
    {
      name: '生物成绩',
      max: 100
    },
    {
      name: '物理成绩',
      max: 100
    },
  ]

  const detail = [{
      value: ['135', '140', '110', '97', '92', '95'],
      name: "张三",
    },
    {
      value: ['120', '110', '128', '90', '100', '98'],
      name: "赵四",
    },
    {
      value: ['100', '123', '150', '88', '90', '87'],
      name: "王五",
    }
  ]
  return {
    color: colors,
    tooltip: {
      confine: true,
      enterable: true, //鼠标是否可以移动到tooltip区域内
      formatter: function (param) {
        return param.name + '\n' +
          indicators[0].name + ':' + param.value[0] + '\n' +
          indicators[1].name + ':' + param.value[1] + '\n' +
          indicators[2].name + ':' + param.value[2] + '\n' +
          indicators[3].name + ':' + param.value[3] + '\n' +
          indicators[4].name + ':' + param.value[4] + '\n' +
          indicators[5].name + ':' + param.value[5] + '\n'
      }
    },
    legend: {
      data: ['张三', '赵四', '王五'],
      left: '0%',
      top: '7%',
      itemWidth: 10,
      itemHeight: 10,
      icon: 'circle',
      textStyle: {
        fontSize: 10,
        color: '#666666'
      }
    },
    radar: {
      splitNumber: 5,
      radius: 100,
      axisLine: {
        show: false
      },
      lineStyle: {
        fontSize: 10,
      },
      indicator: indicators,
      center: ['50%', '55%'], 
      name: {
        textStyle: {
          center: ['10%', '20%'],
          fontSize: 10,
        }
      },
    },

    barGap: '0%',
    series: [{
        name: '张三',
        type: 'radar',
        symbolSize: false,
        data: [{
          value: detail[0].value,
          name: detail[0].name,
        }],
        areaStyle: {
          normal: {
            color: 'rgba(252,157,154,0.5)', 
          }
        },
        itemStyle: {
          normal: {
            lineStyle: {
              width: 0.5,
              color: 'rgba(252,157,154,1)',
              type: 'solid'
            }
          },
        },
      },
      {
        name: '赵四',
        type: 'radar',
        symbolSize: false,
        data: [{
          value: detail[1].value,
          name: detail[1].name,
        }],
        areaStyle: {
          normal: {
            color: 'rgba(28,120,135,0.5)' 
          }
        },
        itemStyle: {
          normal: {
            lineStyle: {
              width: 0.5,
              color: 'rgba(28,120,135,1)',
              type: 'solid'
            }
          },
        },
      },
      {
        name: '王五',
        type: 'radar',
        symbolSize: false,
        data: [{
          value: detail[2].value,
          name: detail[2].name,
        }],
        areaStyle: {
          normal: {
            color: 'rgba(255,252,153,0.5)'
          }
        },
        itemStyle: {
          normal: {
            lineStyle: {
              width: 0.5,
              color: 'rgba(255,252,153,1)',
              type: 'solid'
            }
          },
        },
      }
    ]
  }
}

效果呈现:
在这里插入图片描述

如果有问题,欢迎一起讨论,共同进步!初学微信小程序,有问题请指出,谢谢~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值