在Vue项目中,可以通过设置Echarts的color属性来设置图例的颜色。同时,可以通过设置柱子的itemStyle属性来设置柱子的颜色。

首先,需要在Vue组件中引入Echarts:

import echarts from 'echarts'

然后,在Vue组件的mounted钩子中初始化Echarts,并设置图例和柱子的颜色:

mounted() {
  // 初始化Echarts实例
  const chart = echarts.init(document.getElementById('chart'))

  // 设置图例的颜色
  const legendColor = ['#ff0000', '#00ff00']
  
  // 设置柱子的颜色
  const barColor = ['#0000ff']

  // Echarts配置项
  const option = {
    color: barColor,
    legend: {
      data: ['图例1', '图例2'],
      textStyle: {
        color: legendColor
      }
    },
    series: [
      {
        name: '图例1',
        type: 'bar',
        data: [10, 20, 30, 40, 50]
      },
      {
        name: '图例2',
        type: 'bar',
        data: [50, 40, 30, 20, 10]
      }
    ]
  }

  // 使用配置项初始化图表
  chart.setOption(option)
}

在上面的示例中,我们设置了两个图例的颜色分别为红色和绿色,柱子的颜色为蓝色。可以根据需要调整颜色值

vue项目中Echats设置两个图例颜色不同且与柱子颜色不同

原文地址: http://www.cveoy.top/t/topic/iVjO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录