v-chart 图表曲线图(双曲线)

近期有需求做图表,这里且做记录:

参考资料:v-chart 官网:v-charts

vue 相关的组件封装这里用了v-chart里面大多数属性是echart图表相同的。

以下是曲线图的标签使用方式:

<ve-line ref="lineChart" :data="lineData" :colors="colors" :settings="lineSettings" :extend="extendLine" :legend-visible="false" width="100%" height="100%"></ve-line>

 标签属性说明:

1.settings 配置项;

2.extend也可以理解为配置项,

官网解说:

为了能够更方便的设置属性配置项等,可以通过extend属性实现对已配置好的内部属性进行单独的设置, extend为对象类型,对象内的属性可以是函数,也可以对象,也可以是其他类型的值

  • 当属性为函数时,设置的是函数的返回值
  • 当属性为对象时,如果在options中对应的属性为对象(eg: tooltip)或包含对象的数组(eg: series), 对应的配置会被合并,否则将直接覆盖对应的配置

自己在实践中体会吧,个人感觉就是settings的一个扩展配置。

3.colors:当多条线设置不同颜色的时候就会用到该属性;

4.legend-visible - 是否展示图例组件 legend

<ve-line ref="lineChart" :data="lineData" :colors="colors" :settings="lineSettings" :extend="extendLine" :legend-visible="false" width="100%" height="100%"></ve-line>

export default {

  data() {

    this.colors = ['#03C8D5','#40A9F5']; 
    this.extendLine= {
        grid:{
          left:'-4%',
          top:'20%',
          right:"3.6%"
        },
        legend:{
          bottom:'26',
          icon:"circle",
          itemWidth:6,
          itemHeight:6,
          textStyle: {
            color: "rgba(255,255,255,0.8)",
            fontSize:11
          },
         
          
        },
        yAxis: {
          name: "租户(人数)",
          nameTextStyle: {
            color: "rgba(255, 255, 255, 0.6)",
            fontSize:"10",
            align:'center',

          },
          //是否显示y轴线条
          axisLine: {
            show: true,
            lineStyle: {
              color: '#3B63A0', // y轴的颜色 
            },
          },
          // 纵坐标网格线设置,同理横坐标
          splitLine: {
            show: false,
          },
          // 线条位置
          position: "left",
          min: 0,
          max: 200,
          axisLabel:{
            textStyle: {
              color: "rgba(255, 255, 255, 0.6)",//Y轴内容文字颜色
              fontSize:"10",
              align:'right',
            },
          }
          
        },
        xAxis: {
          boundaryGap:false,
          axisLine: {
            show: true,
            lineStyle: {
              color: '#3B63A0',
            },
          },
          axisLabel:{
            interval:0,
            textStyle: {
              color: "rgba(255, 255, 255, 0.8)",
              fontSize:"10",
            },
          },
          axisTick: {
            show: false,
          },
        },
        series(v) {
          v.forEach(i => {
            i.showSymbol= false,
            i.barWidth = 20;
            if(i.name == "注册租户"){
              i.areaStyle= {// new this.$echarts.graphic.LinearGradient(0,0,0,1,[{}])
                normal:{
                  // color:"rgba(3,200,213,0.32)",
                  color: {
                      colorStops: [{
                          offset: 0, color: 'rgba(3,200,213,0.32)' // 0% 处的颜色
                      }, {
                          offset: 1, color: 'rgba(3,200,213,0)' // 100% 处的颜色
                      }],
                      global: false // 缺省为 false
                    }
                }
              }
            }else{
              i.areaStyle= {// new this.$echarts.graphic.LinearGradient(0,0,0,1,[{}])
               normal:{
                //  color:"rgba(64,169,245,0.48)",
                  color: {
                    colorStops: [{
                        offset: 0, color: 'rgba(107,222,255,0.48)' // 0% 处的颜色
                    }, {
                        offset: 1, color: 'rgba(107,222,255,0.14)' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                  }
               }
              }
            }
            
          })
          return v
        },
        tooltip: {
          backgroundColor:'#0C437E',
          boxShadow: '0px 5px 7px 0px rgba(0,0,0,0.1)',
          padding:[2,12],
          textStyle:{
            color:'#ffffff',
            fontSize:'12px',
            lineHeight:24
          },
          extraCssText: 'box-shadow: 0px 5px 7px 0px rgba(0,0,0,0.1)'
        },
       
        
      };
     return {
        lineSettings:{
            labelMap: {
              'date': '时间',
              'num': '注册租户',
              'num2':'流失租户'
            },
            area: true,
        },
        //双曲线图数据
       lineData: {
        columns: ["date", "num","num2"],//第一个参数为维度(横轴,例如时间),其他参数为指标
        rows: [
          {
              "date": "08-31",
              "num": 50,
              "num2":80 
          },
          {
              "date": "09-01",
              "num": 60,
              "num2": 130
          },
          {
              "date": "09-02",
              "num": 68,
              "num2": 80
          },
          {
              "date": "09-03",
              "num": 110,
              "num2": 180
          },
          {
              "date": "09-04",
              "num": 50,
              "num2": 130
          },
          {
              "date": "09-05",
              "num": 60,
              "num2": 60
          },
          {
              "date": "09-06",
              "num": 80,
              "num2": 90
          }
        ],
      },
    }

  }
}

           

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
v-chart 是一个基于 Vue.js 的可视化图表库,可以用来绘制各种类型的图表,包括动态词云图。 以下是使用 v-chart 绘制动态词云图的步骤: 1. 安装 v-chart 可以通过 npm 安装 v-chart: ``` npm install v-charts --save ``` 2. 导入 v-chart 在需要使用动态词云图的页面中,导入 v-chart: ```javascript import VCharts from 'v-charts' Vue.use(VCharts) ``` 3. 准备数据 准备一个包含词语和权重的数组,例如: ```javascript const data = [ { text: 'vue', weight: 100 }, { text: 'javascript', weight: 80 }, { text: 'html', weight: 60 }, { text: 'css', weight: 50 }, { text: 'webpack', weight: 40 }, { text: 'node.js', weight: 30 }, { text: 'npm', weight: 20 }, { text: 'git', weight: 10 } ] ``` 4. 使用 v-chart 绘制动态词云图 在模板中使用 v-chart 组件,设置 type 属性为 wordcloud,设置 data 属性为准备好的数据数组: ```html <template> <v-chart :data="data" type="wordcloud" /> </template> <script> export default { data() { return { data: [ { text: 'vue', weight: 100 }, { text: 'javascript', weight: 80 }, { text: 'html', weight: 60 }, { text: 'css', weight: 50 }, { text: 'webpack', weight: 40 }, { text: 'node.js', weight: 30 }, { text: 'npm', weight: 20 }, { text: 'git', weight: 10 } ] } } } </script> ``` 5. 调整样式 可以通过设置 v-chart 组件的 style 属性来调整动态词云图的样式,例如: ```html <template> <v-chart :data="data" type="wordcloud" :style="{ height: '500px' }" /> </template> ``` 以上就是使用 v-chart 绘制动态词云图的基本步骤。需要注意的是,v-chart 组件只提供了基本的词云图功能,如果需要更多高级功能,可以考虑使用其他词云图库。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值