在vue2中使用echarts

1.安装

npm install echarts --save

2.引入

全局引入(main.js)

import echarts from 'echarts'
Vue.prototype.$echarts=echarts
//如果报错可以使用
import *as echarts from 'echarts'

局部引用(页面script)

import echarts from 'echarts'

3. 创建容器(直接在template里面写上 div容器)

<div id="myChart"></div>

4.配置表格数据(data中)

option = {
  title: {
    text: 'Referer of a Website',
    subtext: 'Fake Data',
    left: 'center'
  },
  tooltip: {
    trigger: 'item'
  },
  legend: {
    orient: 'vertical',
    left: 'left'
  },
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: '50%',
      data: [
        { value: 1048, name: 'Search Engine' },
        { value: 735, name: 'Direct' },
        { value: 580, name: 'Email' },
        { value: 484, name: 'Union Ads' },
        { value: 300, name: 'Video Ads' }
      ],
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }
  ]
};

在官网复制修改数据即可

5.绘制图表(methods)

rawLine(){     
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      myChart.setOption(this.option);
}

6.展示图表

需要讲“绘制图表代码的函数,挂载到mounted”

  mounted() {
    this.drawLine();
  },
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在 Vue2 使用 ECharts 实现 x 轴 y 轴气泡图,你需要先安装 ECharts。 可以通过 npm 或 yarn 安装 ECharts: ```bash npm install echarts --save # 或者 yarn add echarts ``` 安装完成后,在 Vue 组件引入 ECharts: ```javascript import echarts from 'echarts' ``` 然后在组件的 mounted 钩子函数初始化 ECharts 实例: ```javascript mounted () { // 初始化 ECharts 实例 const chart = echarts.init(this.$refs.chart) // 具体的 ECharts 配置 const option = { // 配置项 } // 使用刚指定的配置项和数据显示图表 chart.setOption(option) } ``` 对于气泡图,可以使用 scatter 和 visualMap 组件实现。以下是一个简单的示例: ```javascript mounted () { // 初始化 ECharts 实例 const chart = echarts.init(this.$refs.chart) // ECharts 配置 const option = { xAxis: { type: 'value', scale: true }, yAxis: { type: 'value', scale: true }, visualMap: { min: 0, max: 100, dimension: 2, calculable: true, orient: 'horizontal', left: 'center', bottom: '15%' }, series: [{ type: 'scatter', data: [ [10.0, 8.04, 10], [8.0, 6.95, 30], [13.0, 7.58, 20], [9.0, 8.81, 50], [11.0, 8.33, 80], [14.0, 9.96, 40], [6.0, 7.24, 70], [4.0, 4.26, 90], [12.0, 10.84, 60], [7.0, 4.82, 100], [5.0, 5.68, 10] ], symbolSize: function (data) { return Math.sqrt(data[2]) }, label: { emphasis: { show: true, formatter: function (param) { return param.data[2] }, position: 'top' } }, itemStyle: { normal: { shadowBlur: 10, shadowColor: 'rgba(120, 36, 50, 0.5)', shadowOffsetY: 5, color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{ offset: 0, color: 'rgb(251, 118, 123)' }, { offset: 1, color: 'rgb(204, 46, 72)' }]) } } }] } // 使用刚指定的配置项和数据显示图表 chart.setOption(option) } ``` 在模板添加一个 div 占位符,并设置 ref 属性为 chart: ```html <template> <div ref="chart" style="width: 100%; height: 400px;"></div> </template> ``` 这样就可以在 Vue2 使用 ECharts 实现 x 轴 y 轴气泡图了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奶糖 肥晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值