vue+echarts 图表排名

在这里插入图片描述

<template>
  <div>   
    <div class="gcbodyblock6" style="position: relative">
      <div
        class="box"
        style="
          overflow-y: scroll;
          margin-top: 3px;
          margin-left: 15px;
          font-size: 16px;
          height: 310px;
         "
         >
        <div class="ranktext">         
          <div
            v-for="(item, index) in chartData"
            :key="index"
            :style="{ color: item.color }"
          >
            NO.{{ index + 1 }}
          </div>
        </div>
        <div style="float: left; width: 85%">
          <div v-for="(item, index) in chartData" :key="index">
            <div
              class="barChart"
              :style="{ height: zoomNum * 63 + 'px', zoom: 1 / zoomNum }"
              style="width: 100%; margin: 0 auto"
            ></div>
          </div> 
        </div>   
      </div>
      
    </div>
  </div>
</template>
data() {
    return {
      zoomNum: window.screen.width / 1920, 
      tabActive: "1",
      scheduleData: [],
      noticesData: [],
      scrollHeight2: 0,
      animate: false,
      timer1: null,
      chartData: [
        {
          myData: 1000,
          title: "xxx项目",
          ydata: 90,
          grayBar: 100,
          color: "#fe6500",
        },
        {
          myData: 800,
          title: "xxx项目",
          ydata: 85,
          grayBar: 100,
          color: "#ec9e00",
        },
        {
          myData: 700,
          title: "xxx项目",
          ydata: 74,
          grayBar: 100,
          color: "#54dc54",
        },
   
      ],
    };
  },
 barCharts1() { 
      var echarts = require("echarts");
      var barCharts = document.getElementsByClassName("barChart");     
      for (var i = 0; i < barCharts.length; i++) {       
        var option = {
          backgroundColor: "",
          grid: {
            left: "13px", // 距离dom间距
            right: "21%",
            top: "9%",
            bottom: "-15px",
          },
          xAxis: [
            {
              show: false,
              type: "value",
              axisPointer: {
                type: "shadow",
              },
              // 横坐标 分割线等取消显示
              axisTick: {
                show: false,
              },
              axisLine: {
                show: false,
              },
              splitLine: {
                show: false,
              },
              axisLabel: {
                show: false,
              },
            },
          ],
          yAxis: [
            {
              //左侧文字
              type: "category",
              inverse: true,
              axisLabel: {
                verticalAlign: "bottom",
                align: "left",
                padding: [0, 10, 10, 8],
                textStyle: {
                  fontSize: 14,
                  color: "#fff",
                  fontFamily: "Source Han Sans CN",
                },
                formatter(value, index) {
                  index += 1;
                },
                rich: {
                  rank: {
                    width: 36,
                    height: 20,
                    color: "#00d4fc",
                    align: "center",
                    marginRight: 10,
                  },
                },
              },
              // 纵坐标数据
              data: [this.chartData[i].title], 
              yAxisIndex: 0,
              // 横坐标 分割线等取消显示
              axisTick: {
                show: false,
              },
              axisLine: {
                show: false,
              },
            },
            {
              //右侧文字
              type: "category",
              inverse: true,
              axisLine: {
                show: false,
              },
              axisTick: {
                show: false,
              },
              axisLabel: {
                show: true,
                inside: false,
                verticalAlign: "right",
                // 位置 上右下左
                padding: [0, 0, 0, 5],
                lineHeight: "0",
                // 控制竖着字体颜色
                textStyle: {
                  fontSize: 22,            
                  color: (params) => {    
                    return this.chartData[i].color;
                  },

                  fontFamily: "SourceHanSansCN-Regular",
                },
                formatter: function (value) {
                  return "{x|" + value + "} {y|" + "万}";
                },
                rich: {
                  x: {
                    fontWeight: "bold",
                    fontSize: 17,
                  },
                  y: {
                    fontSize: 10,
                    lineHeight: 1,
                    alignItems: "bottom",
                  },
                },
              },
    
              data: [this.chartData[i].myData], //[1000]//myData,
            },
            {
              //左侧柱状图的Y轴
              // gridIndex: 0,//y轴所在的 grid 的索引
              splitLine: "none",
              axisTick: "none",
              axisLine: "none",
              data: [],
            },
          ],
          series: [
            {
              //顶层间隔
              show: true,
              type: "pictorialBar",
              symbol: "fixed",
              symbolSize: [2, 10],
              symbolMargin: 2,
              symbolRepeat: "repeat",
              barWidth: 6, // 统计条宽度
              itemStyle: {
                normal: {
                  color: "black",
                },
              },
              z: 2,
              data: [this.chartData[i].ydata], //[80]//ydata,
            },
            {
              //中间层
              show: true,
              type: "bar",
              xAxisIndex: 0, //使用的 x 轴的 index,在单个图表实例中存在多个 x 轴的时候有用。
              yAxisIndex: 0, //使用的 y 轴的 index,在单个图表实例中存在多个 y轴的时候有用。
              barGap: "-100%",
              barWidth: "10px", // 统计条宽度
              max: 1,
              labelLine: {
                show: false,
              },
              z: 1,
              itemStyle: {
                normal: {
                  color: (params) => {            
                    return this.chartData[i].color;
                  },                  
                },
              },
              data: [this.chartData[i].ydata], //[80]//ydata,
            },
            {
              //底层背景
              name: "外框",
              show: true,
              type: "bar",
              xAxisIndex: 0, //使用的 x 轴的 index,在单个图表实例中存在多个 x 轴的时候有用。
              yAxisIndex: 2, //使用的 y 轴的 index,在单个图表实例中存在多个 y 轴的时候有用。
              symbolMargin: 0,
              barGap: "-100%",
              barWidth: 16, // 统计条宽度
              itemStyle: {
                normal: {
                  color: "#091a38",
                },
              },
              z: 0,
              data: [this.chartData[i].grayBar], //[100]//grayBar,
            },
          ],
        };
        myChart.setOption(option);
        myChart.resize({
          width: "auto",
          height: "auto",
        });
      }
    },
 mounted: function () {
    this.barCharts1();
  },
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
实现动态绘制图表,可以使用Vue.js做前端框架,使用Echarts.js做图表库。下面是一个简单的实现过程: 1. 在Vue.js中安装Echarts.js。可以通过npm或者cdn的方式来安装。 2. 在Vue.js组件中引入Echarts.js,并初始化一个echarts实例。 3. 在Vue.js的data中定义一个数组,用来存储图表的数据。在mounted生命周期钩子中,设置一个定时器,每隔一段时间就往数据数组中添加一些数据。 4. 在Vue.js的methods中定义一个函数,用来更新图表。在这个函数中,使用echarts实例的setOption方法来更新图表数据。 5. 在Vue.js的template中,添加一个div元素作为图表容器,并设置宽高。在mounted生命周期钩子中,使用echarts实例的init方法初始化图表,并在更新图表数据时调用更新函数。 下面是一个简单的示例代码: ``` <template> <div id="chart" style="width: 600px; height: 400px;"></div> </template> <script> import echarts from 'echarts' export default { data () { return { chartData: [] } }, mounted () { this.chart = echarts.init(document.getElementById('chart')) this.timer = setInterval(() => { this.addData() this.updateChart() }, 1000) }, methods: { addData () { this.chartData.push(Math.random() * 100) }, updateChart () { this.chart.setOption({ xAxis: { type: 'category', data: Array.from({ length: this.chartData.length }, (_, i) => i) }, yAxis: { type: 'value' }, series: [{ data: this.chartData, type: 'line' }] }) } }, beforeDestroy () { clearInterval(this.timer) this.chart.dispose() } } </script> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值