echarts 当需要对个别数据进行个性化定义时

17 篇文章 0 订阅
4 篇文章 0 订阅

option = {
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value'
    },
    series: [{undefined
//直接在data 数据修改
        data: [120, 200, 150, 80, 70,

{

         value:120,
            itemStyle: {
                color: 'blue',
            }
 },

130],
        type: 'bar'
    }]
};

有也可以通过series 下 label formatter修改 柱状图上的文字  如当数据为0时候设置为”“空对象 实现隐藏0数字

const barOption = () => ({
  // title: {
  //   text: '重大活动供餐单位量化等级情况',
  //   right: 'auto',
  //   textStyle: {
  //     fontSize: 16
  //   }
  // },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      // Use axis to trigger tooltip
      type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
    }
  },
  legend: {
    // y: 'bottom',
    itemHeight: 10,
    itemWidth: 10,
    right: 15,
    textStyle: {
      color: '#A3A9AF',
      fontSize: 11
    },
  },
  grid: {
    top: '5%',
    left: '2%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  xAxis: [
    {
      type: 'value',
      minInterval: 1,
      axisTick: {
        show: false
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: '#A3A9AF', // 更改坐标轴文字颜色
          fontSize: 12 // 更改坐标轴文字大小
        }
      },
      axisLine: {
        lineStyle: {
          color: '#f1f3f8'
        }
      },
      // 坐标轴内线的样式
      splitLine: {
        lineStyle: {
          color: '#f1f3f8'
          // type:'dashed'虚线
        }
      },
    }
  ],
  yAxis: [
    {
      type: 'category',

      axisLine: {
        lineStyle: {
          color: '#f1f3f8'
        }
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: '#A3A9AF', // 更改坐标轴文字颜色
          fontSize: 12 // 更改坐标轴文字大小
        }
      },

      axisTick: {
        alignWithLabel: true,
        show: false
      },
      // data: ['outstanding', 'fine', 'normal']
    }
  ],
  // color: ['#3CCA00', '#F8A404', '#F4011E'],
  series: [
    {
      name: '一般',
      type: 'bar',
      stack: 'total',
      label: {
        show: true,

        formatter: params => {
          if (params.value.normal == 0) {
            return ''
          }
        }
      },
      emphasis: {
        focus: 'series'
      },
      itemStyle: {
        color: '#F4011E '
      }
      // data: [220, 182, 191, 234, 290, 330, 310]
    },

    {
      name: '良好',
      type: 'bar',
      stack: 'total',
      label: {
        show: true,
        // color: '#172533'
        formatter: params => {
          if (params.value.fine == 0) {
            return ''
          }
        }

      },
      emphasis: {
        focus: 'series'
      },
      // data: [120, 132, 101, 134, 90, 230, 210]
      itemStyle: {
        color: '#F8A404'
      }
    },
    {
      barWidth: '25',
      name: '优秀',
      type: 'bar',
      stack: 'total',
      label: {
        show: showLable,
        // color: '#172533'
        formatter: params => {
          if (params.value.outstanding == 0) {
            return ''
          }
        }
      },
      emphasis: {
        focus: 'series'
      },
      itemStyle: {
        color: '#3CCA00'
      }
      // data: [320, 302, 301, 334, 390, 330, 320]
    },
  ],

  dataset: {
    // 用 dimensions 指定了维度的顺序。直角坐标系中,
    // 默认把第一个维度映射到 X 轴上,第二个维度映射到 Y 轴上。
    // 如果不指定 dimensions,也可以通过指定 series.encode
    // 完成映射,参见后文。
    dimensions: ['deptName', 'normal', 'fine', 'outstanding'],
    source: [
      // { blackNum: 2, whiteNum: 3, product: "南山局" },
      { deptName: '福田局', outstanding: 0, fine: 0, normal: 0 },
      { deptName: '龙华局', outstanding: 2, fine: 85, normal: 20 },
      { deptName: '福田局2', outstanding: 20, fine: 4, normal: 4 },
      { deptName: '龙华局3', outstanding: 3, fine: 85, normal: 22 },
      { deptName: '福田局4', outstanding: 4, fine: 62, normal: 20 },
      { deptName: '龙华局5', outstanding: 5, fine: 85, normal: 22 },
      { deptName: '龙华1', outstanding: 6, fine: 85, normal: 22 },
      // { deptName: '福田24', outstanding: 4, fine: 64, normal: 20 },
      // { deptName: '龙华35', outstanding: 3, fine: 85, normal: 22 }
      // { product: "白名单", "2015": 83.1, "2016": 73.4, "2017": 55.1 }
      // { product: 'Cheese Cocoa', '2015': 86.4, '2016': 65.2, '2017': 82.5 },
      // { product: 'Walnut Brownie', '2015': 72.4, '2016': 53.9, '2017': 39.1 }
    ]
  }
})
export {
  barOption
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用echarts提供的excel文件导入插件"echarts-xlsx",具体步骤如下: 1. 下载echarts-xlsx插件,可以在GitHub上找到https://github.com/SheetJS/echarts-xlsx 2. 引入相关文件,包括js和css文件 3. 在HTML中添加一个input标签和一个button标签,用于选择和导入excel文件 4. 在JavaScript中绑定button点击事件,使用文件读取器读取excel文件数据 5. 使用echarts的API将数据转换为需要的格式,例如数组或对象 6. 使用echarts的API绘制图表 下面是一个简单的示例代码: HTML部分: ```html <input type="file" id="fileInput"> <button onclick="importExcel()">导入Excel</button> <div id="chart"></div> ``` JavaScript部分: ```javascript // 引入echarts-xlsx插件 <script src="path/to/echarts-xlsx.min.js"></script> // 绑定按钮点击事件 function importExcel() { var fileInput = document.getElementById("fileInput"); var reader = new FileReader(); reader.onload = function(e) { // 读取excel文件数据 var data = e.target.result; var workbook = XLSX.read(data, {type: 'binary'}); var sheetData = workbook.Sheets[workbook.SheetNames[0]]; var jsonData = XLSX.utils.sheet_to_json(sheetData); // 将数据转换为echarts需要的格式 var xAxisData = []; var seriesData = []; for (var i = 0; i < jsonData.length; i++) { xAxisData.push(jsonData[i].x); seriesData.push(jsonData[i].y); } // 绘制图表 var chart = echarts.init(document.getElementById('chart')); var option = { xAxis: { data: xAxisData }, yAxis: {}, series: [{ name: '数据', type: 'line', data: seriesData }] }; chart.setOption(option); }; reader.readAsBinaryString(fileInput.files[0]); } ``` 需要注意的是,echarts-xlsx插件依赖于SheetJS库,需要先引入SheetJS库的js文件。另外,该示例代码只是一个简单的示例,您需要根据自己的实际情况进行修改和优化。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值